سؤال

I have this class:

    [Table("Items", Schema = "Datamodel")]
    public class BaseItem : Identifier
    {
        [Required(ErrorMessage = "Name is required.")]
        [MaxLength(240)]
        public string Name { get; set; }

        public XmlDocument Content { get; set; }

        public BaseItem() { Content = new XmlDocument(); }
        internal BaseItem(string name) : this() { Name = name; }
    }
}

(The Identifier class just defines an extra property Id of type GUID, which is required and by default initialized with a new value. All my POCO classes inherit from this one.)

The problem is the XmlDocument property, which I want to be stored within the database, preferably as type XML so the contents of the XML can be part of my queries. So, is that possible?
If not, what would be the best alternative while keeping the public interface of this class intact?

هل كانت مفيدة؟

المحلول

It might be possible to Serialize the XmlDoc as a Blob but why bother? It's essentially text.

public string ContentText { get; set; }

private _xmlDocuent;    
[NotMapped] 
public XmlDocument Content 
{
  get { return _xmlDocumet ?? (_xmlDocument = new XmlDocuent.Parse(ContentTExt)); }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top