I'm using Entity Framework. I am calling a stored procedure that returns multiple data sets. One of the result sets maps to an entity that I have defined an enumeration for, and have defined a string backing property to receive the result and parse out the enumeration.
public class OrderInfo
{
[Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid orderID { get; set; }
[NotMapped]
public BillingStatus billingStatus { get; set; }
[Required, Column("billingStatus")]
public string billingStatusString
{
get { return billingStatus.ToString(); }
private set { billingStatus = (BillingStatus)Enum.Parse(typeof(BillingStatus), value); }
}
}
Unfortunately, the annotations are ignored when calling db.ObjectContext.Translate( ... ). I get an error message
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandText = "[dbo].[GetOrders]";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
db.Database.Connection.Open();
var reader = cmd.ExecuteReader();
var orders = ((IObjectContextAdapter)db)
.ObjectContext
.Translate<OrderInfo>(reader, "Orders", MergeOption.AppendOnly)
.ToList();
reader.NextResult();
The mappings defined in the data annotations are not respected, and the Translate method tries to bind to the backing property by its actual name billingStatusString
rather than its mapped value, billingStatus
.
A first chance exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.dll
Additional information: The data reader is incompatible with the specified 'Orders.OrderInfo'. A member of the type, 'billingStatusString', does not have a corresponding column in the data reader with the same name.
Anyone know why this is, or have a workaround?