具有特定类型的字符串外键的NHIBERNATE映射



我正在尝试映射nhibernate中的字符串外键。这有效,但字段是varchar(10(。这会导致性能问题,并且由于NH使用了NVARCHAR(4000(,因此脚本正在计时。当我们将SSM中的变量类型更改为VARCHAR(10(以下查询。

我在NHIBERNATE中具有以下设置:

public class Product
{
  ProductCode:string;
}
public class ProductMap : ClassMap<Product>
{
  public ProductMap()
  {
    Id(p=>p.ProductCode);
  }
}
public class Holding
{
  public long HoldingID {get;set;
  public Product Prod {get;set;}
  public decimal SomeValue {get;set;}
}
public class HoldingMap
{
  public HoldingMap()
  {
    Id(h=>h.HoldingID);
    References(h=>h.Product, "ProductCode");
    Map(h=>h.SomeValue);
  }
}

我尝试更改Id(p=>p.ProductCode);,以便更好地键入:

Id(c => c.Code, "portfolio_code").CustomSqlType("varchar(10)");

,但这似乎并没有改变任何东西。有人知道如何使用正确键入的参数生成查询吗?

谢谢

@david Osbourne是正确的,这确实回答了我的基本问题:始终在nhibernate中加密映射,但我会在这里总结。

nhibrenate将始终使用最大场大小作为参数允许通配符,因此强制场长度有些风险。如果您确实需要,则可以在链接答案中看到驱动程序中的答案。

我的问题实际上是由NH在VARCHAR字段上使用nvarchar引起的。通过将列更改为"存在",我将花费的时间从40秒删除到子秒。

最新更新