Saleh
Saleh

Reputation: 3032

"Only primitive types are supported in this context"

I have got this exception in the last line of my code:

Unable to create a constant value of type 'System.Linq.EnumerableQuery`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

My Code:

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
}

What is wrong with my code?

Upvotes: 0

Views: 6755

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

I believe that the problem is Query. The exception says that you cannot pass EnumerableQuery to Linq-to-entities. If Query is IEnumerable try to rewrite first query as:

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

Upvotes: 3

Related Questions