Does CustomerId help unambiguously identify the string passed by @Id? I really did not execute the โtriggersโ bit, because the predicate used for updating is unknown by the trigger. Or do you want to re-update CustomerId every time (defined with UPDATE(...) in a trigger)
The easiest option is to do this as an update to an object:
var qry = from product in model.Products where Id == @Id && CustomerId == @CustomerId select product; foreach(Product p in qry) { p.Name = @Name; } model.SaveChanges(); // or whatever the method is in EF
If you know you expect a single entry, you can use:
Product prod = (from product in model.Products where Id == @Id && CustomerId == @CustomerId select product).Single(); prod.Name = @Name; mode.SaveChanges(); // ditto
You could also write it as Entity-SQL, but I'm not sure I will worry personally ... (update: I just checked, and I Don't think Entity-SQL includes DML, so no, you can't - you will have to use either the above or the regular SQL / SPROC command)
source share