Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行添加范围时出错_C#_List_Linq - Fatal编程技术网

C# 执行添加范围时出错

C# 执行添加范围时出错,c#,list,linq,C#,List,Linq,我有这个问题 if (cts.Count > 0) { List<CT> ctList = new List<CT>(); foreach (CT c in cts) { var record = (from records in context.CTS

我有这个问题

if (cts.Count > 0)
            {
                List<CT> ctList = new List<CT>();

                foreach (CT c in cts)
                {
                    var record = (from records in context.CTS
                                  where records.CTId == c.CTId
                                  select new Model.CT
                                  {
                                     CTId = records.CTId,
                                     Code = records.Code,
                                     ShortDescription = records.ShortDescription,
                                     LongDescription = records.LongDescription
                                  }).ToList();

                    ctList.AddRange(record);
                }
            }
if(cts.Count>0)
{
List ctList=新列表();
foreach(CT中的CT c)
{
var record=(来自context.CTS中的记录
其中records.CTId==c.CTId
选择newmodel.CT
{
CTId=records.CTId,
代码=记录。代码,
ShortDescription=记录。ShortDescription,
LongDescription=记录。LongDescription
}).ToList();
ctList.AddRange(记录);
}
}
我试图完成的内容:我正在浏览cts列表中的每个CT类型对象。一旦我找到了每个CTS对象的记录,我想更新ctList,所以最后我们得到了不同CTS的记录。现在我在AddRange行上遇到错误。它说:


错误CS1503参数1:无法从“System.Collections.Generic.List”转换为“System.Collections.Generic.IEnumerable”
谢谢您的建议。它为我指明了正确的方向。我添加了一个名为MapEntity的方法,该方法将DAL映射到模型。此错误已为我清除。

您不了解错误的哪一部分?@SLaks我了解我试图将DAL记录分配给列表CT的错误??在执行AddRange之前是否需要执行其他类型的转换?您有两种
CT
类型,一种
DAL.CT
和一种
Model.CT
。这些类型不同,因此会出现错误。也许你希望你的
ctList
类型是
List
?哇,下一票是什么?我自己无法解决这个问题,所以我来到这里,注意到
Model.CT
DAL.CT
被认为是不同的类型(并且是不可行的),即使定义相同