Reputation: 21
I want to convert a SQL query to an ADO.NET Entity Framework LINQ query. I'm working with MySQL.
SQL:
Update Not As n
Inner Join user As a
On a.UserId = n.Not_UserId
Set Not_Checked='0'
Where n.Not_Checked='1'
And n.Not_UserId='" + Not_UserId + "'
LINQ:
var n5 = from u in db.user
join n in db.not
on u.UserId equals n.Not_UserId
where n.Not_Checked==1 && n.Not_UserId==4
select new
{
u,
n
};
I want to update the value of n
. I've tried n5.n
but it didn't work. How to update n
using LINQ EF?
Upvotes: 1
Views: 3204
Reputation: 109253
I think you're looking for something like this:
foreach (var x in n5.ToList())
{
x.n.Not_Checked = 0;
}
db.SaveChanges();
Note that n5
is an IQueryable
, so you have to loop through to get to the element(s), or do FirstOrDefault()
to get the first one.
Upvotes: 2