Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this questionHow can I search in a table if a record with specific parameter doesn't exist, and then insert the record into table?
MyDataContext db = new MyDataContext();
if (db.table.Where( x => x.ID == id).ToList().Count == 0 )
{
db.table.Add(MyRow);
context.SubmitChanges();
}
if(from t in context.table where t.field.Equals(parameter) select t).Count() == 0)
{
  table t = new table(){ field1 = param1, field2 = param2};
  context.table.InsertOnSubmit(t);
  context.SubmitChanges();
}
And remember to enclose it in a transaction for possible concurrency issues.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论