Monday, 15 July 2013

Fluent NHibernate - Is it possible to map a property to a persisted computed column in Sql Server -



Fluent NHibernate - Is it possible to map a property to a persisted computed column in Sql Server -

i want map readonly property computed column in sql server using fluent nhibernate. property substring of one. create substring indexable , have improve search performance. when utilize formula function in mapping, property not map computed column in database computed when using query.

class="lang-cs prettyprint-override">class person{ public virtual string name {get; set;} public virtual string subname {get; set;} } class personmap : classmap<person>{ map(p => p.name); map(p => p.subname).generated.always().formula("substring(name, 0, 5)"); }

you need replicate functionality in code - if alter name property, nhibernate not default send new query database evaluate generated properties.

you need like:

public virtual string subname { { homecoming name.substring(0, 5); } set { } }

note need empty setter otherwise nhibernate complain

edit: see want index column in database, need create computed column table in database. has nil nhibernate, , can either ignore column exclusively in mapping (so long replicate in code), or drop .formula(..) part (since that's specified in computed column already)

nhibernate fluent-nhibernate fluent-nhibernate-mapping calculated-columns database-indexes

No comments:

Post a Comment