Unmapped Columns in NHibernate?

后端 未结 5 928
梦如初夏
梦如初夏 2020-12-20 07:31

I\'m working with a legacy database in Oracle and some of my tables have columns that are set to NOT-NULL that I don\'t want in my domain model, but, obviously, I need to sp

5条回答
  •  孤城傲影
    2020-12-20 08:07

    If you don't want to pollute your POCOs, an Interceptor probably is the best option. Take a look at various articles about interceptors, like this one.

    On your interceptor, you'd want to check the type so you know which fields to put dummy data in. Make sure you use currentState[] in the OnFlushDirty method (OnFlushDirty is "update") and state[] in the OnSave method ("insert"). For example (OnSave):

    if (entity is Group)
    {
        state[Array.IndexOf(propertyNames, "Indentation")] = "dummy value";
        return true;
    }
    return false;
    

    Edit:

    You're trying to insert data that doesn't exist in your domain but is required by your database model, so the above wouldn't quite work for you. Instead, you'll have to add an element to each of the state, propertyNames, and types arrays.

提交回复
热议问题