Mapping EF Entity Columns with Translate <T>
I am using Entity Framework. I call a stored procedure that returns multiple datasets. One of the result sets displays the entity that I defined for the enumeration, and defined the string support property to get the result and parse 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, annotations are ignored when db.ObjectContext.Translate (...) is called. I get an error
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 the actual name billingStatusString to the backing property, rather than its display value, billingStatus .
The first case of an exception of type "System.Data.Entity.Core.EntityCommandExecutionException" occurred in EntityFramework.dll
Additional Information: The data reader is not compatible with the specified "Orders.OrderInfo". An element of type 'billingStatusString' does not have a corresponding column in the data reader with the same name.
Does anyone know why this is, or a workaround?
No one has answered this question yet.
See similar questions:
or similar: