chris vietor
chris vietor

Reputation: 2060

Entity Framework & Webservice

i need some help here.

i have a solution with 2 projects. First project includes a web services, that offers some methods like GetAllCustomers, GetCustomerByGUID etc... It also includes the edmx file, so these "Get" methods give away entity objects.

Second project is - at this moment - a console application to test all these methods. I receive my objects through the web service, everythings fine, but..

Here is my problem:

These objects miss every navigation property. My Customer entity object has some of them. In the web service project, the navigation properties are there.

Another strange thing: If i instanciate the EF DataContext in the Console, i can't call the SaveChanges method. It's just not there. I know i should not have a object of the datacontext in this layer, but for testing i stumbled upon this.

Anyone knows about this?

Upvotes: 1

Views: 1317

Answers (1)

Josh
Josh

Reputation: 44916

You are going to have a difficult time getting this to work the way you have it designed. Remember that once the entity gets serialized and sent across the wire, you lose all information that was associated with the DataContext.

Also, unless you specifically included a reference to the assembly with the Entity Framework Models and chose to reuse those types, then the types you are dealing with are only representative clones of the actual Models in your .edmx.

The navigation properties only make sense when the entity is attached to a DataContext, since that is what handles all the magic of calling the database and hydrating the entity being requested. You are essentially getting a POCO from your web service, but you are trying to use it as though it were still attached to its context.

What you are trying to build is an N-Tier application, so I would suggest reading up on how to do this with Entity Framework.

Upvotes: 2

Related Questions