简体   繁体   English

linq c# 无法创建“”类型的常量值。 在此上下文中仅支持原始类型或枚举类型

[英]linq c# Unable to create a constant value of type ''. Only primitive types or enumeration types are supported in this context

So I have the list that I want to join against a table on the db.所以我有一个列表,我想加入数据库中的一个表。

I am getting the error Unable to create a constant value of type, what am I doing wrong?我收到错误无法创建类型的常量值,我做错了什么?

List<info.user> studyAccessList = new List<info.User>();

using (var Db = new Entities())
{
    //get users from USER table
    var UserDbQry = (from data in Db.USER
                    where data.System == "something" & data.Active == true
                    select data);
    

    //outer join 
    var joinQry = 
        from s1 in UserDbQry
        join t2 in studyAccessList
        on new
        {
           Study = s1.Study,
           Email = s1.Email
        }
        equals new
        {
           Study = t2.Study,
           Email = t2.Email
        }
        into rs
        from r in rs.DefaultIfEmpty()
        //where r == null
        select s1;

    foreach (var inactiveUser in joinQry)
    {
        //add tag for system.
        //create xml 
        string xml = String.Format("<User><Study>{0}</Study><Email>{1}</Email><Active>false</Active></User>", inactiveUser.Study, inactiveUser.Email);
        recordCount = recordCount + ProcessXml(wsu, xml, log.ErrorMsgPrefix);
    }
}

I needed to change the first query to a list then the second query was able to pick it up.我需要将第一个查询更改为一个列表,然后第二个查询才能获取它。

//get users from USER table
var UserDbQry = (from data in Db.USER
                where data.System == "something" & data.Active == true
                select data).ToList;

//outer join 
var joinQry = 
from s1 in UserDbQry
join t2 in studyAccessList
on new
{
   Study = s1.Study,
   Email = s1.Email
}
equals new
{
   Study = t2.Study,
   Email = t2.Email
}
into rs
from r in rs.DefaultIfEmpty()
//where r == null
select s1;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# - Linq:无法创建类型的常量值在此上下文中仅支持基本类型或枚举类型。 - C# - Linq : Unable to create a constant value of type Only primitive types or enumeration types are supported in this context. 无法创建类型为“匿名类型”的常量值。 在此上下文中仅支持原始类型或枚举类型。 在Linq C#中 - Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context. in Linq C# LINQ,无法创建XXX类型的常量值。在此上下文中仅支持基元类型或枚举类型 - LINQ, Unable to create a constant value of type XXX. Only primitive types or enumeration types are supported in this context LINQ查询错误:无法创建类型的常量值。 在此上下文中仅支持原始类型或枚举类型 - LINQ Query error: Unable to create a constant value of type. Only primitive types or enumeration types are supported in this context Linq 到实体框架:无法创建“”类型的常量值。 在此上下文中仅支持原始类型或枚举类型 - Linq to Entity Framework : unable to create a constant value of type ''. Only primitive types or enumeration types are supported in this context 无法创建类型为“匿名类型”的常量值。 在此上下文中仅支持原始类型或枚举类型两个db Linq查询 - Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context two db Linq query 无法创建类型“”的常量值。 在此上下文中仅支持原始类型或枚举类型。 ASP.NET MVC LINQ EF - Unable to create a constant value of type ''. Only primitive types or enumeration types are supported in this context. ASP.NET MVC LINQ EF EF错误无法创建类型为“匿名类型”的常量值。 在此上下文中仅支持原始类型或枚举类型 - EF error Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context EntityFramework无法创建“匿名类型”类型的常量值。 在此上下文中仅支持基元类型或枚举类型 - EntityFramework Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context 无法创建“匿名类型”类型的常量值。 在此上下文中仅支持基元类型或枚举类型 - Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM