Does WCF Data Services support working with Entity Framework Code First (4.1)? It seems like it's having a hard time understanding what to do with DbSet
or DbContext
. I suppose this shouldn't be too surprising since EFCF was released after Data Services.
internal class Context:DbContext {
public Context(String nameOrConnectionString) : base(nameOrConnectionString) { }
public DbSet<AlertQueue> Alerts { get; set; }
}
public class EntitySet:Abstract.EntitySet {
public EntitySet(String nameOrConnectionString) {
var context = new Context(nameOrConnectionString);
this.AlertQueueRepository = new Concrete.AlertQueueRepository(new Repository<AlertQueue>(context, context.Alerts));
}
}
public class AlertQueueRepository:EntityRepository<AlertQueue> {
public AlertQueueRepository(IEntityRepository<AlertQueue> entityRepository):base(entityRepository) { }
public IQueryable<AlertQueue> Pending {
get {
return (from alert in this.All
where alert.ReviewMoment == null
select alert);
}
}
}
EntityRepository
and IEntityRepository
provide generic methods for All
and other CRUD functions. This is the WCF Data Service that isn't working:
public class WcfDataService1:DataService<Domain.Concrete.AlertQueueRepository> {
public static void InitializeService(DataServiceConfiguration config) {
config.SetEntitySetAccessRule("All", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}