How do I create a function mapping a SQL stored procedure?
I have tried
var order = context.CustomerDetails.SqlQuery("DisplayTotalOrders @CustomerID", new SqlParameter("CustomerID", "1"));
var order = context.CustomerDetails.SqlQuery("DisplayTotalOrders @CustomerID", 1);
but nothing has worked.
Error message is shown as below. And this method seems quite an ad-hoc execution. Is there a way destined to create a method which binds a SQL Server stored procedure in EF? I am not talking about just INSERT, UPDATE, DELETE functions. I am referring to executing any SQL Server stored procedure.
Unhandled Exception: System.Data.Entity.Core.EntityCommandExecutionException: The data reader is incompatible with the specified 'TestEF_Code.CustomerDetail'. A member of the type, 'CustomerID', does not have a corresponding column in the data reader with the same name. at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetMemberOrdinalFromReader(DbDataReader storeDataReader, EdmMember member, EdmType currentType, Dictionary
2 renameList) at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetColumnMapsForType(DbDataReader storeDataReader, EdmType edmType, Dictionary
2 renameList) at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary2 renameList) at System.Data.Entity.Core.Objects.ObjectContext.InternalTranslate[TElement](DbDataReader reader, String entitySetName, MergeOption mergeOption, Boolean streaming, EntitySet& entitySet, TypeUsage& edmType) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters) at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69
1.b__68() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69
1.b__67() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters) at System.Data.Entity.Internal.Linq.InternalSet
1.<>c__DisplayClass11.b__10() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.Single[TSource](IEnumerable
1 source) at TestEF_Code.Program.Main(String[] args) in B:\Users\trio\Programming\TestEF-Code\TestEF-Code\Program.cs:line 17