none
Using EF with WCF RRS feed

Answers

  • Bill,

    The DbContext has an associated DbContextConfiguration object which is stored in the Configuration property on your DbContext.  See if you can change it through that.


    Tom Overton
    • Marked as answer by Bill_Yeager Monday, September 5, 2011 9:22 PM
    Monday, September 5, 2011 5:28 PM

All replies

  • The problem might be that you need to set ProxyCreationEnabled = false on the context.   This will take out all the change tracking stuff off the Customer entities so they can be serializable.  Do this before getting your customer list from EF:

    MyContext.ContextOptions.ProxyCreationEnabled = false;
    



    Tom Overton
    • Proposed as answer by r.burgundy_ Tuesday, September 6, 2011 6:22 AM
    Monday, September 5, 2011 5:02 PM
  • Tom, I am using the slimmed down DbContext object from EF instead of the ObjectContext object. It appears I don't have those objects availabile in my DbContext object.

    namespace YeagerTechModel
    {
        public partial class YeagerTechEntities : DbContext
        {
            public YeagerTechEntities()
                : base("name=YeagerTechEntities")
            {
            }
     
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
     
            public DbSet<Category> Categories { getset; }
            public DbSet<Customer> Customers { getset; }
            public DbSet<Priority> Priorities { getset; }
            public DbSet<Project> Projects { getset; }
            public DbSet<Status> Status { getset; }
            public DbSet<TimeTracking> TimeTrackings { getset; }
        }
    }


    This was done right clicking on the model within VisualStudio and selecting "Add Code Generation Item" and then selecting ADO.NET DbContext Code Generator.

    Bill Yeager

    • Edited by Bill_Yeager Monday, September 5, 2011 5:26 PM
    Monday, September 5, 2011 5:18 PM
  • The only issue is a searialization issue coming back from EF (see my WCF trace innerException msg below). If I just can find out how to resolve this, I'm sure the issue will be resolved.

    There was an error while trying to serialize parameter http://tempuri.org/:GetCustomersResult. The InnerException message was 'Type 'System.Data.Entity.DynamicProxies.Customer_9A2613B6CA7308313CA6AFB73C7D3CADDC5412C329C3E778EAFF02F7337EE423' with data contract name 'Customer_9A2613B6CA7308313CA6AFB73C7D3CADDC5412C329C3E778EAFF02F7337EE423:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.


    Bill Yeager
    Monday, September 5, 2011 5:22 PM
  • Bill,

    The DbContext has an associated DbContextConfiguration object which is stored in the Configuration property on your DbContext.  See if you can change it through that.


    Tom Overton
    • Marked as answer by Bill_Yeager Monday, September 5, 2011 9:22 PM
    Monday, September 5, 2011 5:28 PM
  • Tom , thank you so much for your reply! That fixed this long standing issue. Congrats to you :)

    In my web searches, this solution had not come up at all.


    Bill Yeager
    Monday, September 5, 2011 9:21 PM
  • Bill,

    I'm glad it worked for you.  The DbContext is a very new object to the framework, so probably not a lot of web searches would pull up solutions involving it yet.  

    That ProxyCreationEnabled property is something that's good to put in your bag of tricks, whenever an  entity needs to be serialized.  For example if you're doing any ASP.NET web forms development you'll also want to also set it to false before retrieving an entity that you plan to store in viewstate. 

     


    Tom Overton
    Monday, September 5, 2011 9:45 PM
  • Thanks for this topic/replies. I had the exact same issue over here.
    Tuesday, September 6, 2011 6:24 AM