Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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# - Fatal编程技术网

C# 将项添加到可观察集合

C# 将项添加到可观察集合,c#,C#,我想把它添加到一个可观察的集合上。但当我这样做时,它并没有添加两个不同的记录,而是添加了两个最新记录的副本 using (var ctx = DB.Get()) { var Indepth = from z in ctx.Interactions where z.ActivityDate >= start && z.ActivityDate <= end && z.Indepth == true

我想把它添加到一个可观察的集合上。但当我这样做时,它并没有添加两个不同的记录,而是添加了两个最新记录的副本

using (var ctx = DB.Get())
   {        
   var Indepth = from z in ctx.Interactions
         where z.ActivityDate >= start && z.ActivityDate <= end && z.Indepth == true
         select new { Indepth = z.Indepth };
         info.SectionInfo = "Indepth Inquiries";
         info.Result = Indepth.Count();
         QuarterlyInfo.Add(info);

  var general = from z in ctx.Interactions
         where z.ActivityDate >= start && z.ActivityDate <= end && z.Indepth == false
         select new { Indepth = z.Indepth };
         info.SectionInfo = "General Inquiries";
         info.Result = general.Count();
         QuarterlyInfo.Add(info);                
        }
使用(var ctx=DB.Get())
{        
var Indepth=从ctx中的z开始。相互作用

其中z.ActivityDate>=start&&z.ActivityDate=start&&z.ActivityDate不确定信息对象是什么,但您正在两个查询中添加它:

     info.SectionInfo = "Indepth Inquiries";
     info.Result = Indepth.Count();
     QuarterlyInfo.Add(info);

     info.SectionInfo = "Indepth Inquiries";
     info.Result = Indepth.Count();
     QuarterlyInfo.Add(info);

这可能是重复的原因?

我正在尝试堆叠两个查询,但我没有添加相同的信息!您将其描述为两行重复的行。但显然您没有看到这是两个不同的查询。抱歉,我的错-我是想将第二个查询复制到文本编辑器中。我想RST_7的意思是您正在重用“info”对象,并在第二个查询中简单地重写其属性,而不是创建一个新的info对象。啊,这更有意义。是否有方法将其添加到集合中,清除它并添加另一个。或者每次都必须创建一个新对象?我创建一个新实例,可能比双重保存快。