Ignore public/internal fields for NHibernate proxy

前端 未结 5 2148
灰色年华
灰色年华 2021-02-12 19:07

I have some entity types that I would like to lazy load. However, they have some internal (assembly) fields they expose, but are not used outside that class. These fields are co

相关标签:
5条回答
  • 2021-02-12 19:25

    I reassembled NHibernate (easier than getting the source and rebuilding) and removed the code that errors on internal/public fields. LazyLoading appears to work just fine without that check. (Although, I'm new to NHibernate and so there are probably scenarios I don't know about.)

    Edit: Ah, there is a property, "use_proxy_validator" that will disable all validation checks. Good enough.

    Fluently.Configure()
        .ExposeConfiguration(fun cfg -> 
            cfg.Properties.Add("use_proxy_validator", "false"))...
    
    0 讨论(0)
  • 2021-02-12 19:33

    You can use the

    [XmlIgnore]
    

    attribute to decorate the fields :)

    0 讨论(0)
  • 2021-02-12 19:37

    Can you use an Interface to declare the fields "used" ?http://nhibernate.info/doc/nh/en/index.html#persistent-classes-poco-sealed

    "Another possibility is for the class to implement an interface that declares all public members"

    I don't know if NH use the same @transient annotation/attribute as the JAVA version to ignore a property in persistent operations.

    0 讨论(0)
  • 2021-02-12 19:44

    You might want to take a look at this page which gives an overview of using F# with Fluent NHibernate.

    Edit I just noticed your username. Am I correct in perhaps thinking that this is your blog? How foolish of me. It does seem to address your problem though, specifically "We start off by disabling LazyLoad because most of the properties are not virtual, and NHibernate will fail to validate the mapping. Instead, we explicitly LazyLoad things, like the Store reference."? Maybe I'm just misunderstanding the problem.

    0 讨论(0)
  • 2021-02-12 19:49

    Just set the lazy property to false,

     <class name="OrderLine" table="OrderLine" lazy="false" >
    

    you can read more in: Must Everything Be Virtual With NHibernate? - http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/

    Ofir, www.TikalK.com

    0 讨论(0)
提交回复
热议问题