私は、同じ基本クラスを継承する多くのLINQクラスを持っています。各Linqクラスには独自のテーブルがあり、基本クラスは別のテーブルへのリンクの一種です。関係を説明しようとします:C#Linqインターフェイスでの照会
//Base Class
abstract class Element<T>
{
public string Name {get; set;}
public string Species {get; set;}
}
public partial class DogElement : Element<DogElement>
{
public int Legs {get; set;}
public bool hasHair {get; set;}
}
public partial class CatElement : Element<CatElement>
{
public bool hasWiskers {get; set}
}
だから、DogElementとCatElementは、データベース内の別々の物理テーブルです。 SpeciesクラスはSpeciesテーブルから読み込みます。私は基本的に、TテーブルをSpeciesテーブルでグループ化し、.Speciesを設定した後にTとして結果を返す、Elementのジェネリック関数を持っていたいと思います。
//Assume T is DogElement for this example
public IQueryable<T> Collection
{
using (DataBase db = new DataBase())
{
var k = from t in db.GetTable<T>()
where t.SomeID == SomeOtherID
select t;
k = { {Legs = 4, HasHair = True, Species = <null>, Name = <null>}, ...}
I basically want a query that will return an IQueryable<DogElement> with Name
and Species set from a join query. What is the best way to set the Name and
Species values?
return k;
}
class抽象要素→抽象クラス要素 –
shenhengbin