C#wpf DbContext无法隐式转换类型
我的代码有问题。在C#wpf DbContext无法隐式转换类型,c#,wpf,visual-studio,entity-framework,C#,Wpf,Visual Studio,Entity Framework,我的代码有问题。在TegevusedProjektis=\u projektService.GetAllTegevusedProjektides上的MainWindowVM.Cs类中它显示以下错误: 我不知道怎么修,有人能帮我吗 MyMainWindowVM.cscode: public class MainWindowVM : BaseVM { private List<Projekt> _projekts; private List<Tegevus>
TegevusedProjektis=\u projektService.GetAllTegevusedProjektides上的MainWindowVM.Cs
类中代码>它显示以下错误:
我不知道怎么修,有人能帮我吗
MyMainWindowVM.cs
code:
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");
}
}
}
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();
}
我已经捕获了下面代码的相关部分
public class MainWindowVM : BaseVM
{
private IProjektInterface _projektService;
public MainWindowVM()
{
_projektService = new ProjektService(new ProjektDbContext());
}
}
public class ProjektService : BaseService
{ }
按原样,ProjektService
不实现IProjektInterface
。您可以通过以下两种方式之一解决此问题
您可以更改私有字段的类型
private ProjektService _projektService;
或者您可以在ProjektService
中实现您的接口
public class ProjektService : BaseService, IProjektInterface
{ }
显示ProjektService
的类定义。我很确定它没有实现您所期望的IProjektInterface
。您是否在按照编译器所述显式转换时出错?添加的ProjektService
codeProjektService.cs似乎不包含函数GetAllTegevusedProjektides?它在服役吗?