本文介绍了ORM和构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找.NET ORM的实现,并且我有一个主要的问题-是否存在不需要数据库中每个字段都具有公共属性的.NET ORM实现?当我看到,我的脑海里响起了一个小铃铛...........................................................................................我坚决相信封装,并且被迫打开我的对象的和服,只是为了使它们与持久性框架一起正常工作,这给了我heebie-jeebies.所有ORM都需要这种可访问性吗?如果没有,请为我提供一些不需要的示例!

I'm looking over .NET ORM implementations, and I have a major burning question - are there any .NET ORM implemenations that don't require public properties for every field in the database? When I see examples like this, a little bell goes off in my head. I firmly believe in encapsulation, and being forced to open the kimono of my objects just to make them work nicely with persistence frameworks gives me the heebie-jeebies. Is this sort of accessibility required in all ORMs out there? If not, please point me to examples of those that don't need it!

推荐答案

NHibernate支持类成员的多重访问策略.公共属性是默认设置,但是您可以告诉NHibernate直接访问您的类的字段.

NHibernate supports mutiple access strategies for class members. Public properties are a de-facto default but you can tell NHibernate to access the fields of your class directly.

例如

<property name="CustomerName" access="field.camelcase-underscore" />

将指示NHibernate在您的类中使用如下声明的字段:

will instruct NHibernate to use a field in your class declared like this:

protected string _customerName;

这篇关于ORM和构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 08:00