using fluent nhibernate, is there anyway to have a private property mapped

后端 未结 3 439
心在旅途
心在旅途 2021-01-06 23:53

i have a field that i want to map as it links to a column in the database but i don\'t want any external class to access this field directly from my code (its only used in p

3条回答
  •  借酒劲吻你
    2021-01-07 00:13

    I think this is what you're looking for.

    Fluent mapping private properties

    There’s been a point of contention for some users of Fluent NHibernate since the beginning, and that’s the lack of a method of mapping private and protected properties on their domain entities.

    The issue stems from our use of lambda expressions for static reflection of your entities, one of the appealing properties of Fluent NHibernate; by utilising expressions we’re able to protect your mappings from refactoring side-effects. However, lambda expressions can only reference properties that are public on an object, so that makes it difficult to use against protected or private properties.

    None of the solutions we have are ideal, we’ll be the first to admit that; but considering Fluent NHibernate was never designed to support these situations, and the limitations C# imposes on us, we’ve got some pretty reasonable choices. Each option comes with its own compromises, so it’s important you pick the method that has the compromises you’re more willing to accept; I’ll outline the pros and cons of each approach.

提交回复
热议问题