Question : EF4 + WCF Self Tracking Entities problem

Hi you all.

I am working on a n-tier application where I use EF4 with self tracking entities. (se following: http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx ).
The only "difference" I have basicly is that I have placed my context.tt "link" into a separate assembly since it is being used by multible services.

Now, to the problem, I have imp EF MembershipProviders ASP.NET style (se following: http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspx?msg=3207050 ) and exposed all methods trough WCF Service. I also have created Client Authentication service for WinfForm (or WPF) clients. All this works.....almost. I am able to retrieve all data from the data source but I am NOT able to update or insert any data. I have been seeking and debugging for 2 days now...and I REALLY need all the help I can get at this point.

Everything looks good when I user test Console application (or a ASP:NET WebApplication) to test my service methods.. I can Create User or Role, I can Update as well without errors but nothing changes in my database. I am using SQL Server 2008 and VS 2010 RC. No method in Membership or Role provider throws an error. I also tried with other tables in my db with same result..se attached code snippet.

when ValidateCustomer runs my customer (or any other in membership) has ObjectState.Added but still it fails and comes back with the error:

Adding a Customer is not allowed.


I have following design in my solution:

1. DataLayer
1.1 DataModel = Self generated from database
1.2 DataModelTypes = T4 Generated Types
1.2 DataModelContext = Se above. (Shares namespace with 1.2)

2 Membership
2.1 EF MEmerbhipProviders = Seperate Class library.

3. Service Contracts = All WCF Service Contracts (Assembly for each service)
4. Service Code = All CB Files for various WCF Services (Assembly for each service)
5. Service Hosts = All WCF Service hosts. Mostly IIS Hosting. (Assembly for each service).

I also have few more class libraries with various helper methods etc but they should not be important on this matter..

Thanks in advance...

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
public bool AddCustomer(Customer customer)
        {
            using (_context = new TT_OnlineEntities())
            {
                _context.Customers.ApplyChanges(customer);
                _context.ObjectStateManager.ChangeObjectState(customer, EntityState.Added);
                ValidateCustomer(customer);
                return _context.SaveChanges() > 0;
            }
        }

//here is the Validating method as well: 

        private void ValidateCustomer(Customer customer)
        {
            ValidationRule(customer.ChangeTracker.State != ObjectState.Deleted, "Deleting a Customer is not allowed.");
            ValidationRule(customer.ChangeTracker.State != ObjectState.Added, "Adding a Customer is not allowed.");
            ValidationRule(customer.ChangeTracker.State == ObjectState.Unchanged || !String.IsNullOrEmpty(customer.CustomerName), "You must submit a name for the Customer.");
            ValidationRule(customer.ChangeTracker.State == ObjectState.Unchanged || !String.IsNullOrEmpty(customer.ModifiedDate.ToString()), "You must submit last modified date for the Customer.");
        }

Answer : EF4 + WCF Self Tracking Entities problem

Random Solutions  
 
programming4us programming4us