0

I am using WCF Data Service 5.0 (v3) with EF 4. Below my configuration with one operation "GetProducts":

public static void InitializeService(DataServiceConfiguration config)
    {
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.UseVerboseErrors = true;
        config.SetServiceOperationAccessRule("GetProducts", ServiceOperationRights.All);
    }

Suppose my Entity Data Model has a class [Product] with fields [Id] as integer and [Price] as decimal. My WCF DataService Operation should returns a collection of [Product] objects.

[WebGet]
public IQueryable<Product> GetProducts()
{
 var productList = new List<Product>();

 //add 4 Products with different Price
 productList.Add(new Product { Price = 50.00m });
 productList.Add(new Product{ Price = 333 });
 productList.Add(new Product{ Price = 2255 });
 productList.Add(new Product{ Price = 55.7m });

 return productList.AsQueryable();
}

My WCF operation should return 4 objects and each object should have different price. Then I call WCF operation on my client side (WinForms app/.Net 4.0). But on the client side I have a 4 the same objects collection with the same price (price from last object).

What could be causing this behavior?

Simon
  • 1
  • 1
    I think the problem is solved here: http://stackoverflow.com/questions/4083547/how-to-consume-wcf-data-service-operations-in-client-net-application "In the WCF Data Services client library, entities with the same primary key are treated as the same instance both for change tracking reasons and so that object graphs behave as you would expect in an object-oriented, reference-tracked environment such as .NET." – Simon Mar 01 '14 at 21:06
  • Yes -- if your ID is database-generated, you'll have to.. well, contact the database. If these are simply DTOs, you should probably use different types, as using arbitrary IDs will be confusing when the client sends them back later (you'll have updates instead of inserts mostly). If you can guarantee that you can generate a unique key from the service (e.g. UUID) then that's OK. If you can guarantee that the client won't ever send them back with the wrong assumptions, I guess your approach may work if you simply assign arbitrary IDs, though you'll have to document the hack heavily. – tne Mar 04 '14 at 13:02

0 Answers0