Issue when trying to read multiplte entity resultsets from a stored procedure
c#, entity-framework, sql-server, stored-procedures
Solution
Well I find an answer myself If seems that table aliases not working and code-first mapping configurations between the entity classes and table name also not taken into account when you call Translate
So I need to specify original table name (MyEntities) instead of MyEntity in this line of code
var entities = Context.ObjectContext.Translate<MyEntity>(reader, "MyEntities", MergeOption.AppendOnly);
Problem
We using EF5.0 and code-first approach with MS SQL Server I have read an article http://msdn.microsoft.com/en-us/data/jj691402.aspx and decided to try the same approach over our database however, suppose that my stores procedure contains a query like this ``` SELECT * from [dbo].[MyEntities] as MyEntity where ID = @ID ``` and code in C# is ``` var entities = Context.ObjectContext.Translate<MyEntity>(reader, "MyEntity", MergeOption.AppendOnly); ``` I am getting at this point An exception of type 'System.InvalidOperationException' occurred in System.Data.Entity.dll but was not handled in user code Additional information: The EntitySet name 'MyDbContext.MyEntity' could not be found. So, obviously it adds some context name as a prefix to the EntitySet name and instead of MyEntity is looking for MyDbContext.MyEntity in the result set. What causes this behaviour and if there is any workaroud (because in example I referenced above it looks quite streightforward and simple and no specific manipulations is needed, except call db.Database.Initialize(force: false); (which I do in my code as well)