Entity Framework MapToStoredProcedures - ignore options

We have a db table that has the following columns.

  • WidgetId (PK)
  • Widgetname
  • WidgetCreatedOn
  • WidgetLastUpdatedOn

We have stored procedures that handle update / delete / insert in the Widget table.

The nested stored proc only takes vizname as a parameter, for example.

  exec Widget_Insert @WidgetName='Foo Widget'

The stored procedure then puts the dates for the WidgetCreatedOn WidgetLastUpdatedOn itself.

A Widget object has the same properties as a table, for example.

  • WidgetId (Key)
  • Widgetname
  • WidgetCreatedOn
  • WidgetLastUpdatedOn

Is it possible to tell MapToStoredProcedures to ignore certain properties, for example.

        modelBuilder.Entity<Widget>()
            .MapToStoredProcedures(s =>
                s.Insert(i => i.HasName("Widget_Insert")
                      .Parameter(a => a.WidgetName, "WidgetName")
                      .Parameter(a => a.WidgetCreatedOn, **dont map it**)
                      .Parameter(a => a.WidgetLastUpdatedOn, **dont map it**)));

We make Code-First

+4
source share
2 answers

MapToStoredProcedures , . , , , - , EF , -.

DatabaseGeneratedOption of Identity Computed proc.

, . proc , . Identity/Computed - , , , .

, . EF , Identity/Computed proc, ( SCOPE_IDENTITY() SQL-). EF , Identity null, , .

, EF5 ( ) , SaveChanges proc, Widget EntityState.Added. , proc , EF DBSet Add.

+1

, (-), . [DatabaseGenerated(DatabaseGeneratedOption.Computed)] . "" , concurrency. A Select * from where .

, , .

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace MyEfNamespace
{

    [MetadataType(typeof(MetaData))]
    public partial class Widget
    {
        public class MetaData
        {
            [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
            public System.DateTime WidgetCreatedOn;

            [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
            public System.DateTime WidgetLastUpdatedOn;

            ...
        }
    }
}
0

All Articles