2

I am writing an application which works with a legacy database (brownfield). I have a couple of tables in which I insert data. These tables have some fields which need values of which I do not want the properties in my domain entities. Is there a way to insert the default value into the field without having to create a property for it my mapping file? I cannot alter the database to create a trigger, so it has to be done via the mapping file/.net application.

Hope someone can help. I hoped I could use a formula, but that doesn't work and I couldn't find any other ways to do it either.

Marijn
  • 10,367
  • 5
  • 59
  • 80
TedOnTheNet
  • 1,082
  • 1
  • 8
  • 23

3 Answers3

2

you could use a private / protected property.
That would mean introducing these fields into your domain model / mappings, but they would be limited to those, and not exposed to whoever uses your entities.
seems like a reasonable compromise to me.

J. Ed
  • 6,692
  • 4
  • 39
  • 55
1

You could use EventListeners

in the OnPostInsert / OnPostUpdate event you can get the db connection and ad-hoc execute a sql query.

Marijn
  • 10,367
  • 5
  • 59
  • 80
Yavor Shahpasov
  • 1,453
  • 1
  • 12
  • 19
0

NH makes it rather easy

using xml see here using FluentNHibernate see here

the basic idea is to use PropertyAccessor on a non existing property which always has the constant value.

Community
  • 1
  • 1
Firo
  • 30,626
  • 4
  • 55
  • 94