So I'm doing something like this, and I need to specifically NOT insert the value for one of the columns, a uniqueidentifier that is defaulted to newid() in the database. How do I do this? The following code is what I want, but doesn't work because the tagID column is getting defaulted to new Guid() -- all zeros and SQL server obviously doesn't allow multiple inserts of the same uniqueidentier in a PK column.
String[] tags = this.TextBoxTags.Text.Split(',');
for (int i = 0; i < tags.Length; i++)
{
tags[i] = tags[i].Trim();
}
if (tags.Length > 0)
{
foreach (String tag in tags)
{
tblDATA_BlogTag blogTag = new tblDATA_BlogTag();
blogTag.blogID = blogPost.postID;
开发者_如何学Python blogTag.tagText = tag;
blogPost.tblDATA_BlogTags.Add(blogTag);
}
}
dbTimecard.SubmitChanges();
using-default-values-in-linq-to-sql
set the Auto-Synch property to OnInsert, in code it looks like...
[Column(AutoSync=AutoSync.OnInsert,IsDbGenerated=true)]
public DateTime Created
{
}
精彩评论