OracleXmlTypeToXElementPropertyHandler
A property handler that maps the Oracle XMLType type into an XElement property.
A property handler that maps the Oracle XMLType type into an XElement property.
The XML text is bound as a
string, which Oracle converts implicitly, and is therefore subject to the string parameter size limit.
Overview
| Name | Description |
|---|---|
| Class | OracleXmlTypeToXElementPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.Oracle |
| Package | RepoDb.Oracle |
| Implements | IPropertyHandler<object, XElement> |
| Column type | The Oracle XMLType type |
| Property type | XElement |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver (an OracleXmlType or a string) into XML text and parses it via XElement.Parse(). null, DBNull, a null OracleXmlType and an empty value are returned as null. |
| Set | Property to database | Converts the XElement into its unformatted XML text via ToString(SaveOptions.DisableFormatting). A null value is written as null. |
Exceptions
| Exception | Thrown When |
|---|---|
ArgumentException |
The type of the value returned by the driver is not supported. |
Usability
Bind the handler to the property that maps to an XMLType column.
Attribute
public class Document
{
public int Id { get; set; }
[Map("content"), PropertyHandler(typeof(OracleXmlTypeToXElementPropertyHandler))]
public XElement Content { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new OracleConnection(connectionString))
{
var content = XElement.Parse("<root><item id=\"1\" /></root>");
connection.Insert(new Document { Id = 1, Content = content });
var document = connection.Query<Document>(e => e.Id == 1).First();
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Document>()
.PropertyHandler<OracleXmlTypeToXElementPropertyHandler>(e => e.Content);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Document, OracleXmlTypeToXElementPropertyHandler>(e => e.Content, new OracleXmlTypeToXElementPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type XElement:
PropertyHandlerMapper.Add<XElement, OracleXmlTypeToXElementPropertyHandler>(new OracleXmlTypeToXElementPropertyHandler(), true);