c# - How to connect 2 tables using LINQ ASP.NET -
images table structure:
id accountid url slides table structure:
id accountid imageid
i have 2 requests:
viewbag.userid = user.id; viewbag.images = context.images.where(c => c.accountid == user.id).select(c => c); viewbag.slides = context.slides.where(c => c.accountid == user.id).select(c => c); question: how can change code viewbag.slides = result slides.imageid = images.id. i'm trying url of image.
you can linq join
var slidesforuser= ( in context.images join b in context.slides on a.id equals b.imageid a.accountid == user.id select b).tolist(); slidesforuser variable list of slides (for recors matches join , condition). if prefer select 1 property (ex :imageurl), update select part select b.imageurl
Comments
Post a Comment