Given the code later in the question, I get the following error from the first EF4 API:
This Roles property is not a supported navigation property. Property item type "IRole" is not a supported entity type. Interface types are not supported.
Basically, I have a repository similar to the following:
public class Repository : IRepository {
private IEntityProvider _provider;
public Repository(IEntityProvider provider) {
_provider = provider;
}
public IUser GetUser(int id) {
return _provider.FindUser(id);
}
}
Note that IRepository.GetUser returns an IUser.
Say my implementation of IEntityProvider looks like this.
public class EntityProvider : IEntityProvider {
public IUser FindUser(int id) {
IUser entity;
using (var ctx = new MyDbContext()) {
entity = (from n in ctx.Users
where n.Id == id
select (IUser)n).FirstOrDefault();
}
return entity;
}
}
The key point here is that the IUser interface has a List <IRole> property called Roles. Because of this, it seems that the Entity Framework code at first cannot figure out which class to use to execute the IRole interface, which requires a property.
POCO, , , EF4.
public interface IUser {
int Id { get; set; }
string Name { get; set; }
List<IRole> Roles { get; set; }
}
public interface IRole {
int Id { get; set; }
string Name { get; set; }
}
public class User : IUser {
public int Id { get; set; }
public string Name { get; set; }
public List<IRole> Roles { get; set; }
}
public class Role : IRole {
public int Id { get; set; }
public string Name { get; set; }
}
? API- EF4?
:
- (List <Role> DbRoles), EF4. , , <IRole> EF4.
- , EF4 , , .