ObjectContext.ExecuteStoreQuery in Entity Framework creates disconnected objects.

.net c# entity-framework

Question

I need to run some custom SQL to return a list of objects from a table. I'm using ExecuteStoreQuery for that.

var q = context.ExecuteStoreQuery<ProductionUnit>(MySelectString, new SqlParameter("@ProductionUnitId", value));

This does result in q containing an ObjectResult collection, but the actual ProductionUnit elements are Detached and their EntityKey is null. This creates a number of issues when trying to work on some of these objects or their relationships. My SQL query returns a result set containing all the columns of the respective ProductionUnits table (and nothing more).

Anything else I need to do in order to have these objects tracked or is this behavior by design?

1
8
2/4/2010 4:44:29 PM

Popular Answer

Solved it myself - you need to use the ExecuteStoreQuery overload which allows you to specify the EntitySet name for your returned entities.

3
2/4/2010 4:54:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow