Only primitive types ('such as Int32, String, and Guid') are supported in this context

后端 未结 1 822
挽巷
挽巷 2020-12-06 02:27

I\'m getting the following error:

Unable to create a constant value of type \'Phoenix.Intranet.Web.ClientSettings.ComponentRole\'. Only primitiv

相关标签:
1条回答
  • 2020-12-06 03:05

    EntityFramework and Linq to SQL both try to translate such queries which a part is in memory and the other part is in Database, to sql IN operator.

    and because your class which roles is an IEnumerable of is not a primitive type it cannot be translated to SQL query.

    you should first fetch from database to memory and then join two lists in memory.

    for example:

     var vla =  (from cir in phoenixEntities.ComponentInRoles.ToList()
                         join role in roles on cir.RoleId equals role.RoleId
                         where cir.ComponentId == cmpent1.ComponentId
                             select role).ToList();
    

    I hope I helped

    0 讨论(0)
提交回复
热议问题