【发布时间】:2016-09-21 09:53:54
【问题描述】:
我使用 NHibernate 和 ClassMapping。我在其中一个属性上创建了一个索引,如下所示:
public class ShopMapping : ClassMapping<Shop>
{
public ShopMapping()
{
Table("Shops");
Id(p => p.Id, m => m.Generator(NHibernate.Mapping.ByCode.Generators.GuidComb));
Property(p => p.CountryCode, m =>
{
m.Length(10);
m.NotNullable(true);
m.Index("ShopCountryCodeIdx");
m.Unique(false);
});
}
}
这会生成名为 ShopCountryCodeIdx 的索引,但我在同一列上还有一个唯一索引,名为“CountryCode”。我尝试了没有 m.Unique(false) 的情况,但没有效果。 我刚搬到一台新电脑。旧电脑:32 位的 VS2012 和新电脑:64 位的 VS2015。 NHirate 版本是相同的(3.4.1.4)。数据库是 MySQL 5.7(在旧机器上我使用 MySQL 5.5)。 这怎么可能?
【问题讨论】:
-
我只是重新运行代码(使用删除数据库对象等)并使用 m.Unique(false) 重新创建表。这仍然会产生一个额外的索引“CountryCode”(不是唯一的)。我忘了说 CountryCode 属性确实存在于几个对象中。所有这些与对象相关的表都有一个额外的索引“CountryCode”。
-
编辑:我猜会遇到一些缓存问题。 CountryCode 索引仍然是“唯一的”... :(
标签: c# mysql nhibernate