我正在使用Ado.Net的预发行版,无法理解我如何在Ado.Net数据服务中使用它。
ObjectContext的代码
public class TradingContext : ObjectContext
{
private static TradingContext _Context;
public static TradingContext Current
{
get
{
if (_Context == null)
{
_Context = BuildContext();
}
return _Context;
}
}
public TradingContext(EntityConnection conn) : base(conn)
{
}
public IObjectSet<Message> Messages
{
get { return CreateObjectSet<Message>(); }
}
private static TradingContext BuildContext()
{
var builder = new ContextBuilder<TradingContext>();
builder.Entity<Message>().Property(x => x.MessageId).IsIdentity();
builder.Entity<Message>().Property(x => x.Xml).HasStoreType("xml");
return builder.Create(new SqlConnection(@"connection string information"));
}
Ado.Net数据服务的代码
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Trading : DataService<TradingContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
问题是Ado.Net数据服务期望一个没有参数的构造函数。 如果我提供构造函数,我将写入基础构造函数?
即使我指定了基本构造函数,如果没有BuildContext
,上下文也不完整在此预发行版中,Ado.Net数据服务不支持实体框架“仅代码”的内容是什么?
答案 0 :(得分:1)
您可以在dataservice类上覆盖受保护的方法:CreateDataSource(),并可以返回ObjectContext的实例。这使得底层提供者构造函数(在本例中为EF)占用一堆构造函数的场景成为可能。
希望这有帮助。
由于 PRATIK