How can I achieve a connection and where in C # MVC is something like Linq or EF Join used?
This is the SQL equivalent I'm trying to achieve.
select * from promotion P JOIN PromotionsClaimed PC on PC.PromotionId = P.objectid where PC.userId = @USERID
This method should return a list of promotions for the user. Firstly, I get a list of all promotions, then I get a composite list of advertised promotions for the user. This is what I still have.
public IList<Promotion> GetRewardsForUser(string userId) { //a list of all available promotions IList<Promotion> promos = _promotionLogic.Retrieve(); //contains a list of Promotion.objectIds for that user IList<PromotionsClaimed> promosClaimed = _promotionsClaimedLogic.RetrieveByCriteria(t => t.userId == userId); //should return a list of the Promotion name and code for the rewards claimed by user, but a complete list of Promotion entities would be fine var selectedPromos = from promo in promos join promoClaimed in promosClaimed on promo.objectId equals promoClaimed.PromotionId select new { PromoName = promo.Name, PromoCode = promo.Code }; return selectedPromos; }
I understand that there are a lot of problems. I am trying to learn Linq and Entity Framework, but I don’t know how to add where clause to IList or if there is an easier way to accomplish this.
It seems to me that there is a way to filter the promotion list, where it contains Promotion.objectId in the promosClaimed list, but I don't know the syntax.
source share