in entity framework code first, how to use KeyAttribute on multiple columns

You can specify the column order in the attributes, for instance: public class MyEntity { [Key, Column(Order=0)] public int MyFirstKeyProperty { get; set; } [Key, Column(Order=1)] public int MySecondKeyProperty { get; set; } [Key, Column(Order=2)] public string MyThirdKeyProperty { get; set; } // other properties } If you are using the Find method of a … Read more

how to update the multiple rows at a time using linq to sql?

To update one column here are some syntax options: Option 1 var ls=new int[]{2,3,4}; using (var db=new SomeDatabaseContext()) { var some= db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList(); some.ForEach(a=>a.status=true); db.SubmitChanges(); } Option 2 using (var db=new SomeDatabaseContext()) { db.SomeTable .Where(x=>ls.Contains(x.friendid)) .ToList() .ForEach(a=>a.status=true); db.SubmitChanges(); } Option 3 using (var db=new SomeDatabaseContext()) { foreach (var some in db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList()) { some.status=true; } db.SubmitChanges(); } … Read more

Database.BeginTransaction vs Transactions.TransactionScope [duplicate]

I found out the answer in Entity Framework 6’s documentation: With the introduction of EF6, Microsoft recommends to use new API methods: Database.BeginTransaction() and Database.UseTransaction(). Although System.Transactions.TransactionScope is still very well supported, it is no longer necessary for most users of EF6. While Database.BeginTransaction() is used only for database related operations transaction, System.Transactions.TransactionScope, in addition … Read more