Linq To Entities 'Only primitive types or enumeration types are supported' Error

后端 未结 4 2079
梦如初夏
梦如初夏 2020-12-01 22:03

I am using LinqPad to test my query. This query works when the LInqPad connection is to my database (LInq to SQL) but it does not work when I change the connection to use my

4条回答
  •  情深已故
    2020-12-01 22:29

    basically it means you are using some complex datatype inside the query for comparison. in your case i suspect from p in this.Plans where p.PlanID == pd.PlanID is the culprit.

    And it depends on DataProvider. It might work for Sql Data Provider, but not for SqlCE data Provider and so on.

    what you should do is to convert your this.Plans collection into a primitive type collection containing only the Ids i.e.

    var integers = PlanDetails.Plans.Select(s=>s.Id).ToList();
    

    and then use this list inside.

    var q = from pd in PlanDetails
            select new {
                pd.PlanDetailID,
                ThePlanName = (from p in integers
                        where p == pd.PlanID
                        select pd.PlanName)
            };
    

提交回复
热议问题