【发布时间】:2018-01-26 13:02:23
【问题描述】:
我的代码有问题。在TegevusedProjektis = _projektService.GetAllTegevusedProjektides; 的MainWindowVM.Cs 类中,它显示以下错误:
我不知道如何解决它,谁能帮助我。
我的MainWindowVM.cs 代码:
public class MainWindowVM : BaseVM
{
private List<Projekt> _projekts;
private List<Tegevus> _tegevused;
private List<TegevusProjektis> _tegevusedProjektis;
private IProjektInterface _projektService;
public MainWindowVM()
{
_projekts = new List<Projekt>();
_tegevused = new List<Tegevus>();
_tegevusedProjektis = new List<TegevusProjektis>();
_projektService = new ProjektService(new ProjektDbContext());
}
public void LoadData()
{
Projektid = _projektService.GetAllProjekts();
Tegevused = _projektService.GetAllTegevused();
TegevusedProjektis = _projektService.GetAllTegevusedProjektides;
}
public List<Projekt> Projektid
{
get { return _projekts; }
set
{
_projekts = value;
base.NotifyPropertyChanged("Projekts");
}
}
public List<Tegevus> Tegevused
{
get { return _tegevused; }
set
{
_tegevused = value;
base.NotifyPropertyChanged("Tegevused");
}
}
public List<TegevusProjektis> TegevusedProjektis
{
get { return _tegevusedProjektis; }
set
{
_tegevusedProjektis = value;
base.NotifyPropertyChanged("TegevusedProjektis");
}
}
}
这是我的ProjectService.cs 代码:
public class ProjektService : BaseService
{
public ProjektService(ProjektDbContext ctx) : base(ctx)
{
}
public List<Projekt> GetAllProjekts()
{
return base.DataContext.Projektid.ToList();
}
public List<Tegevus> GetAllTegevused()
{
return base.DataContext.Tegevused.ToList();
}
public List<TegevusProjektis> GetAllTegevusedProjektis()
{
return base.DataContext.TegevusedProjektides.ToList();
}
public Projekt GetProjektById(int id)
{
return DataContext.Projektid.Where(x => x.ProjektId == id).Single();
}
public Tegevus GetTegevusById(int id)
{
return DataContext.Tegevused.Where(x => x.TegevusId == id).Single();
}
public TegevusProjektis GetTegevusProjektisById(int id)
{
return DataContext.TegevusedProjektides.Where(x => x.TegevusProjektisId == id).Single();
}
【问题讨论】:
-
向我们展示
ProjektService的类定义。我很确定它没有实现您期望的IProjektInterface。 -
在编译器提到的显式转换时是否出错?
-
添加
ProjektService代码 -
ProjektService.cs 似乎不包含函数 GetAllTegevusedProjektides?是在 BaseService 中吗?
标签: c# wpf visual-studio entity-framework