Silverlight-RIA服务-获取插入ID
本文关键字:插入 ID 获取 服务 Silverlight-RIA | 更新日期: 2023-09-27 17:58:17
我在Silverlight应用程序中使用RIA服务以下是Visual Studio 2010、生成的代码
public void InsertDiscussion_topic(discussion_topic discussion_topic)
{
if ((discussion_topic.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(discussion_topic, EntityState.Added);
}
else
{
this.ObjectContext.discussion_topics.AddObject(discussion_topic);
}
}
现在这不会返回插入的ID,我如何获得插入的ID?
谢谢你的帮助!!!
如果您使用WCF RIa服务,您的Id将在DataContext.SubmitChanges()之后自动更新
MyEntity ent = new MyEntity(); //entity that has Id, mapped
//from primary key (Identity) from data base
MyDataContext.MyEntities.Add(ent);
MyDataContext.SubmitChanges(op => { if (!op.HasError) MessageBox.Show(ent.Id.ToString()); });