在下面的 QueryableEntities 方法中,
IEnumerable<Competition>.AsQueryable()
将返回IQueryable<Competition>
由于期待而无法返回的IQueryable<T>
我只能写一种方法来返回IQueryable<Competition>
和IQueryable<Submission>
如果有人知道怎么做,请告诉我,谢谢
public partial class WinBoutsDataContext<T> : System.Data.Linq.DataContext where T : class
{
public IQueryable<T> QueryableEntities
{
get
{
if (typeof(T).Equals(typeof(Model.Competition)))
{
return this.ConvertToCompetitionList(
this.GetTable<Storage.Competition>()).AsQueryable();
}
else if(typeof(T).Equals(typeof(Model.Submission)))
{
return this.ConvertToSubmissionList(
this.GetTable<Storage.CompetitionEntry>()).AsQueryable();
}
}
}
public DataAccess.Model.Competition ConvertToCompetition(DataAccess.Storage.Competition comp)
{
DataAccess.Model.Competition modelComp = new DataAccess.Model.Competition
{
CompetitionID = comp.CompetitionID,
Active = comp.Active,
CompetitionStatusID =
comp.CompetitionStatusID,
Duration = comp.Duration,
EndDate = comp.EndDate,
Entrants = comp.Entrants,
Featured = comp.Featured,
Image = comp.Image,
IsOvertime = comp.IsOvertime,
MaxEntrants = comp.MaxEntrants,
Notes = comp.Notes,
OvertimeDuration = comp.OvertimeDuration,
OvertimeEnd = comp.OvertimeEnd,
OvertimeStart = comp.OvertimeStart,
ParentCompetitionID = comp.ParentCompetitionID,
Prize = comp.Prize, StartDate = comp.StartDate,
SuggestedBy = comp.SuggestedBy,
Summary = comp.Summary,
Title = comp.Title
};
return modelComp;
}
public IEnumerable<DataAccess.Model.Competition> ConvertToCompetitionList(IEnumerable<DataAccess.Storage.Competition> compList)
{
List<DataAccess.Model.Competition> compModelList = new List<DataAccess.Model.Competition>();
foreach (DataAccess.Storage.Competition comp in compList)
{
compModelList.Add(ConvertToCompetition(comp));
}
return compModelList;
}
}