简体   繁体   English

NHibernate属性配置

[英]NHibernate property config

In the NHibernate, I have this config. 在NHibernate中,我有此配置。

 <property name="Name" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a222222229">
      <column name="Name" />
    </property>

what these mean ? 这些是什么意思? msconrlib, version, culture, publicKeyToken ? msconrlib,版本,区域性,publicKeyToken? why we need these ? 为什么我们需要这些? I have worked on Hibernate in java env, I never use these tags. 我在Java env中研究过Hibernate,所以我从不使用这些标签。

Thanks 谢谢

Type describes the .Net CLR type to be used for that property. 类型描述了用于该属性的.Net CLR类型。 In this case an ordinary string. 在这种情况下,是普通字符串。

You dont have to specify it in this case. 在这种情况下,您不必指定它。 There are cases when you want to specify it, for example when you are working with custom types. 在某些情况下,您想指定它,例如在使用自定义类型时。 Or when you want to map a DateTime. 或者当您想映射DateTime时。

Regarding the meaning of the parts of the type: The type is System.String, it is very precisely described regarding assembly name, culture and version. 关于类型各部分的含义:类型为System.String,关于程序集名称,区域性和版本非常精确地描述。 The publicKeyToken is a key for a strong name for the assembly - this allows for duplicate assembly names as long as they are signed with different keys. publicKeyToken是程序集强名称的密钥-只要使用不同的密钥对程序集名称进行签名,就可以使用重复的程序集名称。

You could write this mapping as 您可以将此映射编写为

 <property name="Name">
      <column name="Name" />
 </property>

or 要么

<property name="Name" type="String">
      <column name="Name" />
</property>

But if you wanted to use a custom type in some assembly you would need to specify if more detailed like you are doing right now. 但是,如果您想在某个程序集中使用自定义类型,则需要指定是否像现在这样更详细。

In MS .Net it's called Strong assembly name. 在MS .Net中,它称为“强程序集”名称。 It's how specific type is identified in .Net Framework. 这是在.Net Framework中标识特定类型的方式。 So this particular string states that to use System.string from mscorlib library with version 4.0. 因此,此特定字符串说明要使用mscorlib库4.0版中的System.string。 with no preferences on localization. 没有本地化偏好。 This allows .Net to use assemblies deployed to GAC - Global Assembly Cache which acts as a global directory of system dlls. 这允许.Net使用部署到GAC的程序集-全局程序集缓存,该程序充当系统dll的全局目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM