我有2个执行查询的类,它们仅在entityD的单个联接上有所不同:它在entityC上联接。第一或entityC。第二
class First
{
protected IQueryable<entityA> GetQuery()
{
return from entityA in DbContext.EntitiesA
join entityB in DbContext.EntitiesB on entityA.Id equals entityB.PropertyA.Id
join entityC in DbContext.EntitiesC on entityB.Id equals entityC.PropertyB.Id
join entityD in DbContext.EntitiesD on entityD.Id equals entityC.FirstPropertyC.Id
join entityE in DbContext.EntitiesE on entityD.Id equals entityE.PropertyD.Id
where ..... select entityA;
} }
class Second
{
protected IQueryable<entityA> GetQuery()
{
return from entityA in DbContext.EntitiesA
join entityB in DbContext.EntitiesB on entityA.Id equals entityB.PropertyA.Id
join entityC in DbContext.EntitiesC on entityB.Id equals entityC.PropertyB.Id
join entityD in DbContext.EntitiesD on entityD.Id equals entityC.SecondPropertyC.Id
join entityE in DbContext.EntitiesE on entityD.Id equals entityE.PropertyD.Id
where ..... select entityA;
} }
是否有可能将这个查询推广到一个共同的基础,并通过某种覆盖方法提供特定的联接?
还是只能概括哪里条款?
class Common
{
protected virtual ??? OverridenMethod (???)
protected IQueryable<entityA> GetQuery()
{
return from entityA in DbContext.EntitiesA
join entityB in DbContext.EntitiesB on entityA.Id equals entityB.PropertyA.Id
join entityC in DbContext.EntitiesC on entityB.Id equals entityC.PropertyB.Id
join entityD in DbContext.EntitiesD on entityD.Id equals OverridenMethod().Id
join entityE in DbContext.EntitiesE on entityD.Id equals entityE.PropertyD.Id
where ..... select entityA;
} }
class OverridenFirst : Common
{
protected override ??? OverridenMethod(???) { return entityC.FirstPropertyC;}
}
class OverridenSecond : Common
{
protected override ??? OverridenMethod(???) { return entityC.SecondPropertyC;}
}