I'm using Microsofts suggested solution for using Entity Framework to read multiple record sets from a stored procedure but added a small snippet to use parameters and it's not working. I've had a co-worker look at the code and tell me it looks like it should work so I thought I'd ask here.
Using the 4.5 framework is not an option. I'm stuck with 4.0 and etity framework 4.4.
App MyApp = (App)Application.Current;
EnterpriseEntities EE = new EnterpriseEntities();
EE.Database.Connection.ConnectionString = MyApp.EnterpriseEntityConnectionString;
var cmd = EE.Database.Connection.CreateCommand();
cmd.CommandText = "[dbo].[spSelectWaterUsesByRightID]";
var param = cmd.CreateParameter();
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int32;
param.ParameterName = "@RightID";
param.Value = this.RightID;
cmd.Parameters.Add(param);
EE.Database.Connection.Open();
var reader = cmd.ExecuteReader();
List<WaterUses> ListOfWaterUses = (((System.Data.Entity.Infrastructure.IObjectContextAdapter)EE)
.ObjectContext
.Translate<WaterUses>(reader, "WaterUses",System.Data.Objects.MergeOption.AppendOnly)).ToList();
When I get to the ExecuteReader line I get an error message that the stored procedure requires Parameter @RightID but that's what I'm passing. I checked the parameter count right before it executes and it's at 1.