c# - How to link a review entity back to a profile entity with an entity in between in entity framework? -
i have profile entity, space entity, , spacereview entity space.
profile -> space -> spacereview
how construct review entity leads profile. when pull reviews can fetch profile info (photo, name, etc) each reviewer?
or should stick int id of reviewer profile field in spacereview , when fetch reviews, go , fetch each , every profile id have saved?
ex. field in spacereview int, no ref profile
public int reviewerid {get; set;} here entities
public class profile { public virtual icollection<space> spaces { get; set; } } public class space { public int profilerefid { get; set; } [foreignkey("profilerefid")] public virtual profile profile { get; set; } public virtual icollection<spacereview> spacereviews { get; set; } } public class spacereview { public int spacerefid { get; set; } [foreignkey("spacerefid")] public virtual space space { get; set; } // link profile entity here!! // not sure how } so when fetch reviews space can profiles , names, images, etc of people made review.
something kinda this.
dbcontext.space.where(i => i.id == someid).select(i => i.spacereviews).select(i => new result {text = i.text, rating = i.rating, reviewername = i.profile.name, profileimage = i.profile.profileimage}
Comments
Post a Comment