我第一次使用Ado.net实体框架,我需要在将其插入数据库之前检查该记录是否存在.我最好搜索是否存在AuthodSSID而不是密钥(AuthorID).我正在使用VS2010,Framework 4. System.Data.Entity是3.5.0.0.
我用Google搜索,但没有找到这个问题的答案.
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
}
Run Code Online (Sandbox Code Playgroud)