2
votes

I got Entity Framework DbContext to work locally, connecting directly to the SQL database.

Now I am trying to put the Entity Framework stuff behind a WCF Service. The WCF Service will exposes its own set of service layer objects (DataContracts) corresponding to the underlying Entities. The client never knows about the underlying data store and entities.

  • Getting data is easy, just a LINQ to SQL and .ToList();
  • Inserting new objects is not too bad, pass a DataContract from the client to the WCF service via its OperationContract then WCF will call DbContext.Add(), DbContext.SaveChanges();

But how do I do an update? Do I need to preserve the PK? If so, what is the usual way of doing it?

You help is appreaciated. Thanks.

1
i'm not sure what you mean by 'pass a datacontract from client to service' - that sounds like leakage to me. regardless, yes, the client should know the PK of the entity it wants to update. - Jason
pass the service datacontract from the client to the service. is that ok? - Jake

1 Answers

0
votes

Yes, you need to keep the primary keys around. I put them in the client facing objects themselves. You can pass them back as part of the object when the client is retrieving the data so that they can in turn pass it back to you on an update.

If the PK name doesn't really fit your abstraction, just call it something else, your services just need to know the mapping.