Tuesday, May 17, 2011

Entity Framework and POCO - No Support for Xml or Enums

I have been keeping up to some pace on Entity Framework, however did not try a lot on it.
So thought of doing a sample on POCO support with Entity Framework.

This was a class I used to insert to my database.
public class Task
{
public long TaskID { get; set; }
public XElement TaskParameter{get;set;}
public string TaskType { get; set; }
public DateTime EnquedTime { get; set; }
public DateTime CompletedTime { get; set; }
public Guid TaskIdentifier { get; set; }
public TaskStatus TaskStatus { get; set; }
public string ErrorDescription { get; set; }
public TaskPriority TaskPriority { get; set; }
}

The property TaskParameter is an XML column in the database and the properties TaskStatus and TaskPriority are enums and are implemented as smallint in the database

Now, I try to instantiate a context and i get this error...

"Mapping and metadata information could not be found for EntityType Task"

To find out the issue is that EF does not support entity mapping to XElement and you have to map the XML column to a string in the entity and that the EF does not support translating back to enums :(

This works perfectly fine in LINQ to SQL , but why is this feature not available in EF? Here is a post to why...

You would also get this error if , your POCO does not implement all properties that are defined in the Entity model and should match the name given in the model.

No comments:

Post a Comment