实体框架 - 在插入/更新时返回多列
当我将实体对象插入上下文或更新它时,实体框架会生成带有指向主键的 RETURNING 子句的查询。
伪代码:
class Job {
//Primary key
public int ID { get; set; }
//Identifier generated via "before insert" postgresql trigger
public string JobIdentifier { get; set; }
public string Name { get; set; }
}
using (var context = CreateEFContext())
{
var job = new Job() {
Name = "test job",
}
context.Job.Add(job);
context.SaveChanges();
//the job identifier is empty
var generatedJobIdentifier = job.JobIdentifier;
}
上面的代码将通过 INSERT
查询上的 RETURNING
子句仅返回 ID
列,但我对 ID< /code> 和
JobIdentifier
值,无需在更新或插入后立即调用另一个查询。 我的问题是如何通过一些附加设置指示实体框架在 INSERT
查询上返回多个列?
When I insert entity object to the context or update it, Entity Framework generates query with RETURNING
clause pointing to the primary key.
Pseudo code:
class Job {
//Primary key
public int ID { get; set; }
//Identifier generated via "before insert" postgresql trigger
public string JobIdentifier { get; set; }
public string Name { get; set; }
}
using (var context = CreateEFContext())
{
var job = new Job() {
Name = "test job",
}
context.Job.Add(job);
context.SaveChanges();
//the job identifier is empty
var generatedJobIdentifier = job.JobIdentifier;
}
Above code will return only ID
column via RETURNING
clause on INSERT
query, but I'm interested in both ID
and JobIdentifier
values without calling another query just moment after update or insert.
My question is how could I instruct Entity Framework to return multiple columns on INSERT
query via some additional settings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论