I want to allow 3rd party code to extend an NHibernate mappings at run time. This is what I have now:
Sql:
TABLE Orders
Id INT identity,
[more fields...]
Code in my project:
public interface IOrder
{
int Id { get; set; }
// more properties...
}
internal class Order : IOrder
{
public int Id { get; set; }
}
public class OrderDAL
{
public IEnumerable<IOrder> GetOrders()
{
ICriteria criteria;
// build some criteria
var result = criteria.List<Order>();
RaiseOrdersLoaded(result);
return result;
}
}
NHibernate hbm file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="..." assembly="...">
<class name="Order" table="Orders">
<id name="Id" column="Id" type="int" >
<generator class="identity" />
</id>
[more properties...]
</class>
</hibernate-mapping>
The 3rd party is a dll I load with Ioc. It knows the interface IOrder
but not the Order
class. Its developer is also adding a table in my database:
TABLE OrderExtension
OrderId PK, FK from Orders
CustomField nvarchar
Now the 3rd party developer should be able to do:
- Add his
CustomField
to the query inGetOrders
. I thought about extending the hbm file in run time but I don't know how. - Add criteria to the query to filter by his
CustomField
. - Listen to
OrdersLoaded
event and get his data somehow.
Is all this possible?
Thanks