我有这些类(从他们删除冗余信息后):
public class Category : BaseEntity { public virtual Category ContainingCategory { get; set; } public virtual IList<CategoryProperty> Properties { get; set; } } public class CategoryProperty : BaseEntity { public virtual string Name { get; set; } public virtual IList<CategoryPropertyValue> Values { get; set; } } public class CategoryPropertyValue : BaseEntity { public virtual string Name { get; set; } } public class CategoryPropertyValueCollection : BaseEntity { public virtual IList<CategoryPropertyValue> Values { get; set; } } public class Product : BaseEntity { public virtual string Name { get; set; } public virtual Category ContainingCategory { get; set; } public virtual IDictionary<CategoryProperty, CategoryPropertyValueCollection> Properties { get; set; } }这些是我的映射(再次删除冗余信息后):
public class CategoryMap : BaseMap<Category> { public CategoryMap() { Map(x => x.Name); HasMany(x => x.Properties); } } public class CategoryPropertyMap : BaseMap<CategoryProperty> { public CategoryPropertyMap() { Map(x => x.Name); HasMany(x => x.Values); } } public class CategoryPropertyValueMap : BaseMap<CategoryPropertyValue> { public CategoryPropertyValueMap() { Map(x => x.Name); } } public class CategoryPropertyValueCollectionMap : BaseMap<CategoryPropertyValueCollection> { public CategoryPropertyValueCollectionMap() { HasMany(x => x.Values).Cascade.None(); } } public class ProductMap : BaseMap<Product> { public ProductMap() { Map(x => x.Name); HasMany(x => x.Properties).AsEntityMap(); } }我的映射出了问题,很容易看出我想要实现的目标(ebay将成为该逻辑的一个很好的例子 - 来自具有不同属性和可能值的类别的产品可以过滤)。 这是我得到的表(不好):
create table Categories ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, ContainingCategoryId INT null, primary key (Id) ) create table CategoryProperties ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, CategoryId INT null, primary key (Id) ) create table CategoryPropertyValueCollections ( Id INT IDENTITY NOT NULL, ProductId INT null, CategoryProperty_id INT null, primary key (Id) ) create table CategoryPropertyValues ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, CategoryPropertyId INT null, CategoryPropertyValueCollectionId INT null, OrderItemId INT null, CategoryProperty_id INT null, primary key (Id) )为什么' CategoryPropertyValues '是使用' CategoryPropertyValueCollectionId '列创建的? 我在映射中做错了什么?
I have this classes (after removing redundant information from them):
public class Category : BaseEntity { public virtual Category ContainingCategory { get; set; } public virtual IList<CategoryProperty> Properties { get; set; } } public class CategoryProperty : BaseEntity { public virtual string Name { get; set; } public virtual IList<CategoryPropertyValue> Values { get; set; } } public class CategoryPropertyValue : BaseEntity { public virtual string Name { get; set; } } public class CategoryPropertyValueCollection : BaseEntity { public virtual IList<CategoryPropertyValue> Values { get; set; } } public class Product : BaseEntity { public virtual string Name { get; set; } public virtual Category ContainingCategory { get; set; } public virtual IDictionary<CategoryProperty, CategoryPropertyValueCollection> Properties { get; set; } }And those are my mapping (after removing redundant information again):
public class CategoryMap : BaseMap<Category> { public CategoryMap() { Map(x => x.Name); HasMany(x => x.Properties); } } public class CategoryPropertyMap : BaseMap<CategoryProperty> { public CategoryPropertyMap() { Map(x => x.Name); HasMany(x => x.Values); } } public class CategoryPropertyValueMap : BaseMap<CategoryPropertyValue> { public CategoryPropertyValueMap() { Map(x => x.Name); } } public class CategoryPropertyValueCollectionMap : BaseMap<CategoryPropertyValueCollection> { public CategoryPropertyValueCollectionMap() { HasMany(x => x.Values).Cascade.None(); } } public class ProductMap : BaseMap<Product> { public ProductMap() { Map(x => x.Name); HasMany(x => x.Properties).AsEntityMap(); } }Something is wrong with my mappings, it's easy to see what I'm trying to accomplish (ebay will be a good example of that logic - products from categories that has properties that varies and possible values to filter by). This is that tables I'm getting (which aren't good):
create table Categories ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, ContainingCategoryId INT null, primary key (Id) ) create table CategoryProperties ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, CategoryId INT null, primary key (Id) ) create table CategoryPropertyValueCollections ( Id INT IDENTITY NOT NULL, ProductId INT null, CategoryProperty_id INT null, primary key (Id) ) create table CategoryPropertyValues ( Id INT IDENTITY NOT NULL, Name NVARCHAR(255) null, CategoryPropertyId INT null, CategoryPropertyValueCollectionId INT null, OrderItemId INT null, CategoryProperty_id INT null, primary key (Id) )Why does 'CategoryPropertyValues' is created with a 'CategoryPropertyValueCollectionId' column? What am I doing wrong in the mapping?
最满意答案
发现我的问题是使用HasMany而不是HasManyToMany 。
Found out my problem was the usage of HasMany instead of HasManyToMany.
更多推荐
public,class,set,Properties,电脑培训,计算机培训,IT培训"/> <meta name="d
发布评论