![](/img/trans.png)
[英]how to get the max value of id from second table using join in entity framework in asp.net c#
[英]Get id of new record from mssql using entity in asp.net c#
我需要獲取新創建的記錄形式mssql的ID。 我閱讀了一些信息,但仍不清楚。 它說我可以做以下事情:
using (var context = new MyContext())
{
context.MyEntities.AddObject(myNewObject);
context.SaveChanges();
int id = myNewObject.Id; // Yes it's here
}
夠了嗎
是的,只有您保存了,您才能獲得新的價值
確保設置了Identity屬性
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
看看: C#,實體框架,自動遞增
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.