Suppose I have few records which i want to insert/update through EF.
public partial class Contact
{
public int ContactID { get; set; }
public string ContactPerson { get; set; }
public string EmailID { get; set; }
}
var _Contact = new list<Contact>();
_Contact.add(new Contact(){ContactID=1,ContactPerson="Dev",EmailID="[email protected]"});
_Contact.add(new Contact(){ContactID=2,ContactPerson="Ross",EmailID="[email protected]"});
_Contact.add(new Contact(){ContactID=3,ContactPerson="Martin",EmailID="[email protected]"});
_Contact.add(new Contact(){ContactID=4,ContactPerson="Moss",EmailID="[email protected]"});
_Contact.add(new Contact(){ContactID=5,ContactPerson="Koos",EmailID="[email protected]"});
With the help of a stored procedure, we can detect that any particular records exist or not, if exist then update will execute and if not exist then records will be inserted. i want to do the same through EF.......is it possible ?
I know that I can call SQL Server stored procedures from EF to achieve my goal but I am trying to know if I can do it in EF without calling a stored procedure?
If yes then discuss the same with sample code which check each records exist in db or not and if exist then it will update otherwise will insert. Looking for help.
ContactID?