获得使用LINQ to SQL ID [英] Get Id using LINQ to SQL
问题描述
我怎样才能得到一个记录ID将其保存到数据库之后。我的意思其实是类似的东西。
How can I get a record id after saving it into database. Which I mean is actually something like that.
我的文档类(这是从数据库实体寿),并创建像
I have Document class (which is entity tho from DataBase) and I create an instance like
Document doc = new Document() {title="Math",name="Important"};
dataContext.Documents.InsertOnSubmit(doc);
dataContext.SubmitChanges();
不是我要的是要找回它的id值(的docId),它位于数据库中,它的主键也自动编号。一方面,将有大量的系统上的用户并提交吨的记录那样。
than what I want is to retrieve it's id value (docId) which is located in database and it's primary key also automatic number. One thing, there will be lots of users on the system and submits tons of records like that.
在此先感谢大家:)
推荐答案
一旦运行.SubmitChanges然后doc.docId应该填充在数据库上创建的标识。
Once you have run .SubmitChanges then doc.docId should be populated with the Id that was created on the database.
这篇关于获得使用LINQ to SQL ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!