How to implement custom SQL statements for entity's property in NHibernate
In application I have a bunch of entity class NHibernate mappings with two common properties: {GUID Id, string Tag} (it is implemented through abstract base class).
In DB there are tables for each entity with common columns:
d开发者_如何学Cbo.[EntityName] { uniqueidentifier Id, ... etc. }
Also there is a table that stores information about some global tag for each entity:
dbo.EntityTag { uniqueidentifier Id, nvarchar Tag }
This table is strictly needed and it's mandatory to have it in Db.
How could I implement custom SQL logic to update, select and insert values in Tag property?
For example in FluentNhibernate It would be helpful to have something like
Map(x => x.Tag)
.Insert("INSERT dbo.EntityTag VALUES({Id},{Tag})")
.Update("UPDATE dbo.EntityTag SET Tag={Tag} WHERE Id = {ID}")
.SELECT("...")
.Delete("... etc")
Formally speaking, you can do it using custom implementation of entity persister.
However, in this case, it seems easier to use a <join>
mapping.
精彩评论