인터페이스를 구현하는 모든 테이블을 조회하는 방법 : 내 엔티티 클래스의 일부 인터페이스를 구현 한
public partial class Order : IReportable
{
public string TableName { get { return "Order"; } }
}
public partial class Client: IReportable
{
public string TableName { get { return "Client"; } }
}
public interface IReportable
{
string TableName { get; }
}
그런 다음 나는 DbContext이 추가 :
public virtual DbSet<IReportable> IReportable { get; set; }
I가 때를 여기에 표시된대로이 인터페이스를 구현하는 모든 테이블을 쿼리하십시오.
var result = from reportabletable in db.IReportable
where reportabletable.TableName == table_name
select reportabletable
다음 예외가 발생합니다.
'Report.DataAccess.IReportable'유형이 매핑되지 않았습니다. 또는 NoMappedAttribute 데이터 주석 무시 방법을 사용하여 형식을 명시 적으로 제외하지 않았는지 확인하십시오. 형식이 이 클래스로 정의되었는지, 프리미티브가 아니거나 generic인지, 그리고 EntityObject에서 을 상속받지 않았는지 확인하십시오.
많은 ORM이 해당 쿼리 유형을 제공한다면 놀랄 것입니다. –
@MarcGravell 불가능하다고 말하는가? – enb081
Entity Framework의 상속 전략을 확인하십시오. 나는 그것이 가능하다면 DbSet을 가질 수는 없지만 가상 (또는 아마도 추상적 인) 속성 인 TableName을 사용하여 기본 추상 클래스로이 작업을 수행 할 수 있습니다. Btw. 여기에는 상속 전략에 대한 링크를 확인하는 TableName 속성이 있습니다. http://www.entityframeworktutorial.net/code-first/inheritance-strategy-in-code-first.aspx –