重复的参考键 - Fluent NHibernate Automapping
我在流畅和参考键中自动映射时遇到问题。示例如下:
public class ConfigurationCategory
{
public virtual Guid Id { get; private set; }
[NotNull]
public virtual String Name { get; set; }
public virtual String Description { get; set; }
public virtual String Icon { get; set; }
public virtual ConfigurationCategory Parent { get; set; }
public virtual IList<ConfigurationCategory> Children { get; private set; }
public ConfigurationCategory()
{
Children = new List<ConfigurationCategory>();
}
}
产生以下 SQL 输出:
CREATE TABLE "ConfigurationCategory"
...
parent_id uuid,
configurationcategory_id uuid,
CONSTRAINT "ConfigurationCategory_pkey" PRIMARY KEY (id),
CONSTRAINT fk6ccc850055890dc8 FOREIGN KEY (configurationcategory_id)
REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk6ccc8500ee71b726 FOREIGN KEY (parent_id)
REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
为什么 ConfigurationCategory 重复?
I got a problem with automapping in fluent and reference key. Example would be that:
public class ConfigurationCategory
{
public virtual Guid Id { get; private set; }
[NotNull]
public virtual String Name { get; set; }
public virtual String Description { get; set; }
public virtual String Icon { get; set; }
public virtual ConfigurationCategory Parent { get; set; }
public virtual IList<ConfigurationCategory> Children { get; private set; }
public ConfigurationCategory()
{
Children = new List<ConfigurationCategory>();
}
}
Results in the following SQL-Output:
CREATE TABLE "ConfigurationCategory"
...
parent_id uuid,
configurationcategory_id uuid,
CONSTRAINT "ConfigurationCategory_pkey" PRIMARY KEY (id),
CONSTRAINT fk6ccc850055890dc8 FOREIGN KEY (configurationcategory_id)
REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk6ccc8500ee71b726 FOREIGN KEY (parent_id)
REFERENCES "ConfigurationCategory" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
Why is ConfigurationCategory duplicated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用流畅的自动映射,但我猜它会因为同时拥有 Parent 和 Children 属性而感到困惑;我猜想流利无法判断它们都是由数据库中的同一列处理的。
您可能需要创建一个 ClassMap 并为 References() 和 HasMany() 调用指定键列名称。
I haven't used fluent automapping, but I would guess it is confused by the fact that you have both the Parent and the Children properties; I would guess fluent can't tell that they are both meant to be handled by the same column in the database.
You probably need to create a ClassMap and specify the key column names for both the References() and HasMany() calls.