开发者

Generating a newsequentialid using Linq

I'm inserting a record into a table where Id is of type uniqueidenfier. I would like that Id to be generated on SQL server, sort of like using newsequentialid.

To insert a record I'm using InsertOnSubmit method like so:

 SchedulerDataContext db = new SchedulerDataContext();
 db.Courses.InsertOnSubmit(courseDomainModel);
 db.SubmitChanges();

update: a开发者_JS百科s the answer stated I need to set 'Default value or Binding' property of a column to newid(). Here is the screenshot of it for reference.

Generating a newsequentialid using Linq


From the msdn-link above

NEWSEQUENTIALID() can only be used with DEFAULT constraints on table columns of type uniqueidentifier.

When NEWSEQUENTIALID() is used in DEFAULT expressions, it cannot be combined with other scalar operators.

NEWSEQUENTIALID() cannot be referenced in queries.

That means you can not set it from LINQ, you need to put it in the table definition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜