【发布时间】:2012-03-06 10:40:23
【问题描述】:
我是第一次使用 Ado.net 实体框架,我需要在将其插入数据库之前检查此记录是否存在。最好我会搜索 AuthodSSID 是否存在而不是密钥(AuthorID)。我正在使用 VS2010,Framework 4。System.Data.Entity 是 3.5.0.0。
我用谷歌搜索,但没有找到这个问题的答案。
PublishingCompanyEntities publishContext;
publishContext = new PublishingCompanyEntities();
private void createNew_Click(object sender, EventArgs e)
{
Author newAuthor = new Author();
newAuthor.FirstName = firstName.Text;
newAuthor.LastName = lastName.Text;
newAuthor.AuthodSSID = 20;
newAuthor.AuthorID = 10
//Check if record exist here
publishContext.AddToAuthor(newAuthor);//insert if does not exist
}
【问题讨论】:
-
旧但看起来仍然像 DUP;更多信息请访问stackoverflow.com/questions/1802286/…
标签: c# entity-framework