指定要在Insert上返回的列

时间:2015-11-05 19:43:02

标签: .net oracle entity-framework entity-framework-6

给定像

这样的实体
class Foo
{
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public int SometimesComputed { get; set; }
}

在插入时,生成的SQL将返回SometimesComputed的值:

INSERT 
...
RETURNING "SometimesComputed" INTO "SometimesComputed"
OPEN :p0 FOR SELECT "SometimesComputed" AS "SometimesComputed" FROM DUAL;

哪个好。但是,DatabaseGeneratedOption.ComputedDatabaseGeneratedOption.Identity的警告是,我在插入前为SometimesComputed指定的任何值都将被忽略,并替换为DB计算值。

var foo = new Foo { SometimesComputed = 42 };
context.DbSet<Foo>().Add(foo);
context.SaveChanges();

// foo.SometimesComputed will be whatever the next sequence value was, not 42

是否可以让实体框架执行RETURNING ... INTO OPEN FOR SELECT无论如何?无论我指定一个值,是否由触发器设置,只需返回插入的值。

0 个答案:

没有答案