NHibernate 将字符串参数转换为 nvarchar 而不是 varchar。我怎样才能阻止这个?
我有一个映射到视图的类,并且正在搜索名字和姓氏以搜索患者记录。该视图最终查看患者表上的名字和姓氏字段(也可能是其他字段,具体取决于输入)。当条件转换为 SQL 时,它会将我的字符串作为 nvarchar 参数输入。我已经在映射中使用了 type="AnsiString" 和 length="50",但它仍然将它们转换为 nvarchar,这对我的查询造成了性能影响。
<class name="PatientSearchResult" table="vw_PatientSearch" mutable="false" >
<id name="Id" type="Guid" column="PatientId"/>
<property name="MedicalRecordNumber" type="AnsiString" length="50" />
<property name="Title" />
<property name="FirstName" type="AnsiString" length="50" />
<property name="MiddleName" />
<property name="LastName" type="AnsiString" length="50" />
<property name="Nickname" />
<property name="Suffix" />
<property name="DateOfBirth" />
<property name="IsRestricted" />
<property name="IsDeleted" />
<component name="Address">
<property name="StreetAddress1" />
<property name="StreetAddress2" />
<property name="City" />
<property name="State" />
<property name="PostalCode" />
</component>
</class>
SQL Profiler 将输出 SQL 显示为使用 nvarchar 参数,并在所有字符串前添加 N 前缀以进行转换。
我错过了什么吗?在标准或映射方面还需要做些什么吗?另外,参数的长度也不是常数50。我正在使用 NHibernate 2.1。
I have a class mapped to a view and am searching on first and last names in order to search for patient records. The view ultimately looks at the first and last name fields on the patient table (possibly others as well depending on input). When the criteria converts to SQL, it's entering my strings as nvarchar parameters. I've already used type="AnsiString" and length="50" on my mapping, but it still is converting these to nvarchar, which is causing a performance hit on my query.
<class name="PatientSearchResult" table="vw_PatientSearch" mutable="false" >
<id name="Id" type="Guid" column="PatientId"/>
<property name="MedicalRecordNumber" type="AnsiString" length="50" />
<property name="Title" />
<property name="FirstName" type="AnsiString" length="50" />
<property name="MiddleName" />
<property name="LastName" type="AnsiString" length="50" />
<property name="Nickname" />
<property name="Suffix" />
<property name="DateOfBirth" />
<property name="IsRestricted" />
<property name="IsDeleted" />
<component name="Address">
<property name="StreetAddress1" />
<property name="StreetAddress2" />
<property name="City" />
<property name="State" />
<property name="PostalCode" />
</component>
</class>
SQL Profiler is showing the output SQL as using nvarchar parameters and prefixing all of my strings with N to cast them.
Am I missing something? Is there anything else that needs to be done on the criteria or the mapping? Additionally, the length of the parameters is not a constant 50 either. I am using NHibernate 2.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在映射中使用 sql-type 属性:
您遇到了什么性能问题?在我看来,将字符串视为 unicode 不太可能对性能产生太大影响。
Try using the sql-type attribute in your mappings:
What performance issues are you having? It seems unlikely to me that treating strings as unicode would affect performance all that much.
试试这个
Try this