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?

+3
c # entity-framework
Aug 23 '16 at 0:33
source share

No one has answered this question yet.

See similar questions:

2
Dynamic translation to avoid C # syntax errors

or similar:

783
Entity Framework vs LINQ to SQL
758
Entity Framework 5 Record Update
756
Verification failed for one or more objects. See the topic "EntityValidationErrors Property" for more information.
630
The fastest way to embed Entity infrastructure
515
How can I get the ID of an inserted object in an Entity framework?
461
How to view SQL generated by Entity Framework?
443
SqlException from Entity Framework - No new transaction allowed because there are other threads in the session
401
Entity Framework service provider not found for ADO.NET provider with the invariant name "System.Data.SqlClient"
392
Failed to load Entity Framework provider type?
328
Entity cannot be built in LINQ to Entities query



All Articles