我不知道它是否足够,但你可以用这样的东西来控制它:
public override bool Equals(object obj)
{
T other = obj as T;
if (other == null)
return false;
// handle the case of comparing two NEW objects
bool otherIsTransient = Equals(other.Id, Guid.Empty);
bool thisIsTransient = Equals(Id, Guid.Empty);
if (otherIsTransient && thisIsTransient)
return ReferenceEquals(other, this);
return other.Id.ToUpper().Equals(Id.ToUpper());
}
在比较实体时使用 ToUpper() 或 ToLower() 方法,或者您可以使用 String.Compare(stringA,strngB,StringComparison.OrdinalIgnoreCase)。
如果您想要更多控制权并且这是您的目标,您可以创建自定义 ID 生成器,如下所述:
http://nhibernate.info/doc/howto/various/creating-a-custom-id-generator-for-nhibernate.html
更新
您是否尝试过创建自定义 GetIgnoreCase(...)?
我认为也可以通过加载器标记覆盖实体映射文件中默认 Get 方法生成的 SELECT 语句,如下例所示:
...
<loader query-ref="loadProducts"/>
</class>
<sql-query name="loadProducts">
<return alias="prod" class="Product" />
<![CDATA[
select
ProductID as {prod.ProductID},
UnitPrice as {prod.UnitPrice},
ProductName as {pod.ProductName}
from Products prod
order by ProductID desc
]]>
您可以尝试修改返回大写 ID 的 select 语句。
更新
经过进一步调查,我认为使用拦截器可以解决您的问题!
在这里阅读:
http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11-interceptors-and/1nr4enxv3dpeq/14#
更多文档在这里:
http://blog.scooletz.com/2011/02/22/nhibernate-interceptor-magic-tricks-pt-5/
类似这样的:
public class TestInterceptor
: EmptyInterceptor, IInterceptor
{
private readonly IInterceptor innerInterceptor;
public TestInterceptor(IInterceptor innerInterceptor)
{
this.innerInterceptor = this.innerInterceptor ?? new EmptyInterceptor();
}
public override object GetEntity(string entityName, object id)
{
if (id is string)
id = id.ToString().ToUpper();
return this.innerInterceptor.GetEntity(entityName, id);
}
}
并像这样流利地注册它:
return Fluently.Configure()
...
.ExposeConfiguration(c =>{c.Interceptor = new TestInterceptor(c.Interceptor ?? new EmptyInterceptor());})
...
.BuildConfiguration();