So, you have a couple of options here. I have a tip on this very issue, and a robust answer:
Generic Entity Framework AddOrUpdate Method with Composite Key Support[
^]
Now, if all you want is basic support for one single table that will just update a couple of values, you can do the following:
public void InsOrUpdate(int id, int pid, int cId)
{
var cP = _uoW.Com.Find(id);
if (cP != null)
{
cP.PId = pId;
cP.CId = cId;
_uoW.Entry(cP).State = EntityState.Modified;
}
else
{
cP=new Comp
{
Id = id;
PId = pid;
CId = cId;
};
_uoW.Entry(cP).State = EntityState.Added;
}
_uoW.SaveChanges();
}