locked
WCF Data Services 5.0 + DbContext + Reuse Types option... RRS feed

  • Question

  • Hi,

    I'm testing out WCF Data Services 5.0 and I want to share the assembly declaring my entities between the service and the client. The problem is that, even though I check the "Reuse types in all assemblies" option while adding the service reference, Visual Studio generate proxies for my entities.

    Here's how I've setup my projects:

    EntitiesProject (Class Library)

    This project host my 'Contact' entity defined as follow:

    public class Contact
    {
      public int Id { get; set; }
      public string Name { get; set; }
    }

    ServiceProject (WCF Service Application) 

    This project host the DbContext and the WCF Data Service and reference the EntitiesProject assembly.

    The DbContext is defined as follow:

    public class TestContext : DbContext
    {
      public DbSet<Contact> Contacts { get; set; }
    }

    The WCF Data Service is defined as follow:

      public class TestService : DataService<TestContext>
      {
        public static void InitializeService( DataServiceConfiguration config )
        {
          config.SetEntitySetAccessRule( "*", EntitySetRights.AllRead );
          config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
      }
    

    ClientProject (WPF Application)

    This project reference the EntitiesProject assembly and will add a Service Reference to the TestService.svc.

    So, what can be done so that the client generated code uses the entities defined in my EntitiesProject instead of generating proxies?

    Thank you,

    Jacques.

    Thursday, June 21, 2012 2:34 PM

Answers

  • There is no way to do when you do add "Service Reference" in our client project. But the question is if you want to use the same types in the client, why do you need to do add "Service Reference"? Just use the DataServiceContext and use the types from the common assembly. The only thing you will loose is some strongly typed method on the derived context class, but they are just thin shim over the base DataServiceContext class.

    On the client side, just use the DataServiceContext and use the common types. Please let us know if you run into issues, but that should work.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.


    Wednesday, September 19, 2012 7:06 PM
    Moderator

All replies

  • this problem i don't know too

    but i know some details of this

    public class A:DataService<ObjectContext>{  

            protected override ObjectContext CreateDataSource() {
                var ydbc = new YourDbContext();
                ydbc.Configuration.ValidateOnSaveEnabled = false;
                var oc = ((IObjectContextAdapter)ydbc).ObjectContext;
                return oc;
            }

    }

    but only have this content The same will not succeed. perhaps need some config ,But I still don't know


    project discovery developer

    Wednesday, September 19, 2012 12:15 PM
  • There is no way to do when you do add "Service Reference" in our client project. But the question is if you want to use the same types in the client, why do you need to do add "Service Reference"? Just use the DataServiceContext and use the types from the common assembly. The only thing you will loose is some strongly typed method on the derived context class, but they are just thin shim over the base DataServiceContext class.

    On the client side, just use the DataServiceContext and use the common types. Please let us know if you run into issues, but that should work.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.


    Wednesday, September 19, 2012 7:06 PM
    Moderator