开发者

Need to populate a collection's sub-collection when selecting new

Everything in my Linq query is working properly except for the area where I'm trying to populate a sub-collection with data. (Anything referencing ChannelInfo).

ChannelInfo does appear in Intellisense, so it is recognized as a property of the new OfferType. The right side of my setters for ChannelInfo are also recognized and accessible in intellisense. I really need to create new OfferType objects if possible. Can I reference the sub-connection (ChannelInfo) in such a way that I can get this query to work?

IEnumerable<OfferType> list = (from offerCatType in offerRes.OfferCategory  <=---- OfferCategoryType objects
                       开发者_开发知识库        where offerCatType.type == Type
                               from offers in offerCatType.Offer  <=--- OfferType objects
                               where Convert.ToDateTime(offers.startDate) > MonthYear && Convert.ToDateTime(offers.endDate) < MonthYear
                                     select new OfferType
                                     { 
                                         name = offers.name,
                                         description = offers.description, 
                                         startDate = offers.startDate, 
                                         endDate = offers.endDate, 
                                         ChannelInfo.refClickThroughLink = offers.ChannelInfo.refClickThroughLink,
                                         ChannelInfo.refId = offers.ChannelInfo.refId,
                                         ChannelInfo.refLink = offers.ChannelInfo.refLink 
                                     }
                                 );


select new OfferType
{ 
   name = offers.name,
   description = offers.description, 
   startDate = offers.startDate, 
   endDate = offers.endDate, 
   ChannelInfo = 
   new ChannelInfo 
   { 
      refClickThroughLink = offers.ChannelInfo.refClickThroughLink,
      refId = offers.ChannelInfo.refId,
      refLink = offers.ChannelInfo.refLink 
   };
}

Pardon the syntax. But, you will have to new up the ChannelInfo class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜