views:

378

answers:

1

Im using the pre release of Ado.Net and can't understand how I use that with Ado.Net Data Service.

The code for the 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"));
        }

And the code for Ado.Net Data Service

 [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;
        }
    }

The problem is that Ado.Net Data Service expect a constructor with no parameters. And if I provide a constructor what will I write to the base constructor?

And even if I specify the base constructor the context isn't complete without BuildContext

What have I missed or isn't Entity Framework "code only" not supported with Ado.Net Data Service in this pre release?

+1  A: 

You can override the protected method: CreateDataSource() on your dataservice class, and can return the instance of the ObjectContext. This enables the scenario where the underlying provider constructor(in this case EF) takes a bunch of constructors.

Hope this helps.

Thanks Pratik

Pratik Patel

related questions