“在这种情况下只支持原始类型”

时间:2011-05-22 05:48:56

标签: c# entity-framework

我的代码的最后一行有这个例外:

  

无法创建类型为'System.Linq.EnumerableQuery`1'的常量值。在此上下文中仅支持原始类型(例如Int32,String和Guid')。

我的代码:

using (GharardadhaEntities dal = new GharardadhaEntities())
{
    IQueryable<TBL_Gharardad> Gharardadha =
        from record in dal.TBL_Gharardad
        join shenase in Query on record.PK_Shenase equals shenase
        select record;

    var q = (from record in dal.TBL_MabalegheDariaftieMahane
             where record.TBL_Gharardad == Gharardadha.First()
             select record); 

    ulong v = (ulong)Gharardadha.First().MablagheDariaftiKol;// I have got the error on this statement
}

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:3)

我认为问题是Query。例外情况表示您无法将EnumerableQuery传递给Linq-to-entities。如果QueryIEnumerable,请尝试将第一个查询重写为:

IQueryable<TBL_Gharardad> Gharardadha =
    from record in dal.TBL_Gharardad
    where Query.Contains(record.PK_Shenase)
    select record;