Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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# 具有接口的通用Linq查询_C#_Linq - Fatal编程技术网

C# 具有接口的通用Linq查询

C# 具有接口的通用Linq查询,c#,linq,C#,Linq,我有几个数据库表,它们实现了一个接口IValue;这显然是一个例子,但我不能改变数据库设计: public partial class Table1 : //Linq Table { *int ID {get; set;} *string Name {get; set;} } public partial class Table2 : //Linq Table { *int ID {get; set;} *int Height {get; set;} *in

我有几个数据库表,它们实现了一个接口IValue;这显然是一个例子,但我不能改变数据库设计:

public partial class Table1 : //Linq Table
{
    *int ID {get; set;}
    *string Name {get; set;}

}

public partial class Table2 : //Linq Table
{
   *int ID {get; set;}
   *int Height {get; set;}
   *int Width {get; set;}
}

public partial class Table1 : ValueCollection<Table1>, IValue
{
   double Value {get; set;}
}

public partial class Table2 : ValueCollection<Table2>, IValue
{
   double Value {get; set;}
}
这与做以下事情是一样的:

(from t in db.Table1s
select t);

t将具有ID和Name属性,并且值将被取消分配。

该代码目前看起来很像伪代码。。。结果将没有ID属性,例如。。。请提供您想要优化的完整工作代码。@Claire:我认为您缺少索引器-结果[I]将有一个ID属性,但没有结果变量。我忘记了索引器[I];完全忽略了它。谢谢。但是索引器不存在于易读的…fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
      for (int i = 0; i < results.Count(); i++)
      {
         results[i].Value = (from v in db.Values
                          where v.KeyID = results[i].ID
                          select v.Value).First();
      }

      return results; 
    }
 }
 }
foreach (var s in Table1.Collection) {Console.WriteLine(s.ID)};
(from t in db.Table1s
select t);