Any way for linq query to check against existing select?
Posted
by
danrhul
on Stack Overflow
See other posts from Stack Overflow
or by danrhul
Published on 2012-06-20T09:10:22Z
Indexed on
2012/06/20
9:16 UTC
Read the original article
Hit count: 139
I have an an offer, that can be in any number of categories. I don't however want that offer to then appear twice or however more.
I was wondering if its possible to have a where clause that ascertains whether that offer already exists in that select statement and if so obviously to ignore it.
Here is the linq query:
Offers = from o in offerCategories
orderby o.RewardCategory.Ordering, o.Order
where o.RewardOffer.IsDeleted == false
select new OfferOverviewViewModel
{
Partner = o.RewardOffer.Partner,
Description = String.Format("{0} {1}", o.RewardOffer.MainTitle, o.RewardOffer.SecondaryTitle),
OfferId = o.OfferId,
FeaturedOffer = o.RewardOffer.FeaturedOfferOrder.HasValue,
Categories = from c in offerCategories.Where(oc => oc.OfferId == o.OfferId)
orderby c.RewardCategory.Ordering
select new CategoryDetailViewModel
{
Description = c.RewardCategory.DisplayName
}
},
© Stack Overflow or respective owner