English 中文(简体)
LINQ加入了多种条件
原标题:LINQ join multiple conditions
  • 时间:2011-10-30 07:06:27
  •  标签:
  • linq

我组成了以下准则问题,但造成错误。

mcc_season is not an Depende in mcc_product

我有2个<代码>的问询。 WHERE conditions and both from different entities in the participation

var guestCardProduct =
           (from c in CrmOrgServiceContext.mcc_productpriceSet
            join d in CrmOrgServiceContext.mcc_productSet
            on c.mcc_product.Id equals d.mcc_productId
            where d.mcc_producttype.Value == (int)mcc_product.mcc_producttypeOptionSet.GuestCard
            && c.mcc_season.Id == seasonId
            select new
            {
                d.mcc_productId,
                c.mcc_price
            }).FirstOrDefault();
问题回答

您可以重新做如下工作:

var guestCardProduct = 
           (from c in CrmOrgServiceContext.mcc_productpriceSet 
            where c.mcc_season.Id == seasonId
            join d in CrmOrgServiceContext.mcc_productSet 
            on c.mcc_product.Id equals d.mcc_productId 
            where d.mcc_producttype.Value == (int)c.mcc_product.mcc_producttypeOptionSet.GuestCard 
            select new 
            { 
                d.mcc_productId, 
                c.mcc_price 
            }).FirstOrDefault();

我们在此假设,乳房主之间的关系是1-0.1。 Set and both mcc_season and mcc_product and also a 1 - 0.1 relationship between mcc_product and mcc_producttype 备选案文Set。 如果你在其中任何一种财产之间有1-n关系,那么你就不得不通过这些关系开展工作,而不是把他们混入单一财产,因为你将收集儿童物品而不是一个儿童物品。 你可能认为,把你的询问分成小部分,以缩小问题的根源是有益的。





相关问题
IEnumerable to array of parameter

Using linq? and XML is there a way to convert this IEnumerable to a string array of the value parameter? List<string> idList = new List<string>(); foreach (XElement idElement in word....

linq query for tag system - search for multiple tags

I have two tables, Tags(tagid, postid, tagname) and posts(postid, name, ...) now i want to make a query that returns me all posts that have a generic amount of tags. like: i want all posts that have ...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

How to filter duplicate list items

i have list of items IList with data that looks list this: GenId TestMode 1 0 1 1 3 0 3 1 4 NULL 2 NULL i want to remove the index ...

C# Grouping/Sorting a Generic List<> using LINQ

Im looking to group and sort a Generic List<>. I have a list of objects representing files and each of these objects has a FileName, FileType and FileDate property. FileType is defined as an ...

热门标签