【发布时间】:2014-07-16 11:58:55
【问题描述】:
我创建了 WCF OData 服务,引用了基于 EF6 的项目 DAL。 在这里,我指的是我的 DataContext 的扩展类,称为 MyDbContext。
namespace PScope.DAL
{
public class MyDbContext : DbContext
{
public DbSet<AspNetUser> AspNetUsers { get; set; }
PScopeDB db = new PScopeDB();
public MyDbContext()
: base("name=PScopeDB")
{
}
public IQueryable<Task> TaskList
{
get
{
return db.Tasks;
}
}
}
}
在这个类中,我正在尝试创建一个新方法,该方法很少有连接来返回一个新实体。我使用 WebGet 方法在我的 DataService 类中定义了实体。
namespace PrimariusScope.DataService
{
[JSONPSupportBehavior]
public class DataService : EntityFrameworkDataService<DAL.MyDbContext>, IServiceProvider
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
// config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
public object GetService(Type serviceType)
{
if (serviceType == typeof(IDataServiceStreamProvider))
{
// Return the stream provider to the data service.
return new ImageStreamProvider();
}
return null;
}
// Define a query interceptor for the Resources entity set.
[QueryInterceptor("Resources")]
public Expression<Func<DAL.Resource, bool>> OnQueryResources()
{
return o => o.Active == true;
}
[WebGet]
public IQueryable<DAL.Task> TaskList()
{
DAL.MyDbContext entities = new DAL.MyDbContext();
return entities.TaskList;
}
}
}
但是当我运行我的服务时,TaskList 方法没有公开。 http://localhost:12034/DataService.svc/TaskList 返回未找到。
我在这里错过了什么?
【问题讨论】:
标签: entity-framework-5 wcf-data-services