Linq updating different table after join process
asp.net, c#, join, linq, sql
Solution
Though your approach is a little bit unclear right now (for e.g. we don't know which entities you are trying to update), however you can modify your code like this,
public void updateShoes(Shoe shoe)
{
var query = from b in db.BrandTbls.AsQueryable()
join m in db.ShoeModelTbls on b.BrandID equals m.BrandID
join s in db.ShoeTbls on m.ModelID equals s.ModelID
where shoe.ShoeID == s.ShoeID
orderby m.ModelName
select new
{
Shoe = shoe, Brand = b, Model = m
};
foreach(var o in query)
{
o.Shoe.ColorName = "Black";
o.Brand.BrandName = "New Branding";
o.Model.ModelName = "Something else";
}
db.SaveChanges();
}
Rather picking selected properties from each Entity, you can pick whole entity. Then you can update each entity in a loop as I have doing above.
Problem
I have combined 3 of my tables by using linq join. After that i want to update this table by using data that i get from webform. How can i do this ? My implementation is below ``` public void updateShoes(Shoe shoe) { var query = from b in db.BrandTbls.AsQueryable() join m in db.ShoeModelTbls on b.BrandID equals m.BrandID join s in db.ShoeTbls on m.ModelID equals s.ModelID where shoe.ShoeID == s.ShoeID orderby m.ModelName select new { s.ShoeID, s.Size, s.PrimaryColor, s.SecondaryColor, s.Quantity, m.ModelName, m.Price, b.BrandName }; } ```