In "Entity Framework 4.0 Recipes", Larry Tenny and Zeeshan Hirani state that XML data types are simply not supported by EF 4.0.
They do offer a workaround, which is to make the string type property on the entity class generated by the model private and create a new property (in your own partial class of the entity class) to return an XElement from the internal string property:
public partial class Candidate
{
private XElement candidateResume = null;
public XElement CandidateResume
{
get
{
if (candidateResume == null)
{
candidateResume = XElement.Parse(this.Resume);
candidateResume.Changed += (s,e) =>
{
this.Resume = candidateResume.ToString();
}
}
return candidateResume;
}
set
{
candidateResume = value;
candidateResume.Changed += (s,e) =>
{
this.Resume = candidateResume.ToString();
}
this.Resume = value.ToString();
}
}
}
Creating a shadow property of the desired XML type like this should work, but the conversion between string and XML on every change of the original string property (Resume) and the new shadow property (CandidateResume) is pretty expensive.
If anyone has any better ideas, I'm still open to suggestions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…