I am trying to translate a sql query to Linq to be called from a command in my C# WPF application. I've tried to use Linqer but the query won't translate. I'm new to Linq and have been reading around. Do you use a Linq 'JOIN' to solve this?
update P
set P.versionid=a.versionid
from tbPublicationArticles P, tbarticles a
where P.articleid=a.articlesid
First get your data, joining the 2 tables together:
var results = from p in db.tbPublicationArticles
join a in db.tbarticles on p.articleid = a.articlesid
select new { p, a };
Now you loop through the results and make the changes you require:
foreach(var item in results)
{
item.p.versionid = item.a.versionid;
}
And don't forget to save your changes:
db.SaveChanges();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With