동일한 기본 클래스에서 상속 된 여러 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 테이블에서 읽습니다. 기본적으로 Species 테이블로 T 테이블을 그룹화하고 .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