There is an DLL named DbContract that contains, inter alia, these interface (code is mostly in polish):
public interface IKategoria
{
string Nazwa { get; set; }
IGrupa Grupa { get; set; }
ICollection<IKategoriaUzytkownik> Uzytkownicy { get; set; }
ICollection<IZdarzenie> Zdarzenia { get; set; }
}
Then I want use Entity Framework repositories in another DLL (its not a web application, just a library that knows how to save objects to a database via facede of repositories). So I’m implementing concrete classes for it:
public class Kategoria : BaseObject, IKategoria
{
private string _Nazwa;
private IGrupa _Grupa;
private ICollection<IKategoriaUzytkownik> _Uzytkownicy;
private ICollection<IZdarzenie> _zdarzenia;
public string Nazwa
{
get { return _Nazwa; }
set { _Nazwa = value; }
public Guid GrupaId { get; set; }
public virtual IGrupa Grupa
{
get { return _Grupa; }
set { _Grupa = value; }
}
public virtual ICollection<IKategoriaUzytkownik> Uzytkownicy
{
get { return _Uzytkownicy; }
set { _Uzytkownicy = value; }
}
public virtual ICollection<IZdarzenie> Zdarzenia
{
get { return _zdarzenia; }
set { _zdarzenia = value; }
}
}
So as you can see i need to use IKategoria, IKategoriaUzytkownicy or IZdarzenie (these are all interfaces) so I can’t use this class for Entity Framework because EF need concrete classes to save them in DB (it needs navigation properties).
So my question is: How can I deisgn my architecture so I can use interfaces in applications (web, desktop) and still be able to use Entity Framework as ORM? I don’t want to bend all my Interfaces just because of Entity Framework.
Here is very simplified UML diagram of this how it should look like.