Hello again!
I'm using a mixing of mapping by conventions and specific customization and I tried to use convention to change the name of a column that is mapped as a <element>, but it does not change the column name.
The class in question is:
public class Product : Entity
{
public virtual string Name { get; set; }
public virtual Brand Brand { get; set; }
public virtual Category Category { get; set; }
public virtual Status Status { get; set; }
public virtual string MainImagePath { get; set; }
public virtual decimal UnityPrice { get; set; }
public virtual float Weight { get; set; }
public virtual bool IsFeatured { get; set; }
public virtual string ReferenceCode { get; set; }
public virtual ICollection<string> Images { get; set; }
public virtual ICollection<ProductDetail> ProductDetails { get; set; }
public virtual ICollection<ProductDetail> TechnicalData { get; set; }
public virtual ICollection<Wharehouse> Wharehouses { get; set; }
}
The mapping generated is this:
<class name="Product" table="Products">
<id name="Id" column="ProductId" type="Int64">
<generator class="hilo">
<param name="table">NextHighVaues</param>
<param name="column">NextHigh</param>
<param name="max_lo">100</param>
<param name="where">Entity = 'Product'</param>
</generator>
</id>
...
<set name="Images" table="ProductImages" lazy="true" inverse="true" cascade="save-update, persist">
<key column="ProductId" foreign-key="ProductId_ProductImages" />
<element column="ImagesElement" type="String" length="400" not-null="true" unique="true" />
</set>
...
</class>
I want to change the ImagesElement name in the table, but it's not working.
The code to perform customization is this:
public TablesAndColumnNamingPack(IDomainInspector domainInspector, IInflector inflector)
{
poid = new List<IPatternApplier<MemberInfo, IIdMapper>>
{
new PrimaryKeyColumnNameApplier(),
};
element = new List<IPatternApplier<MemberInfo, IElementMapper>>
{
new ElementNamingApplier(),
};
manyToOne = new List<IPatternApplier<MemberInfo, IManyToOneMapper>>
{
new ManyToOneNamingApplier()
};
propertyPath = new List<IPatternApplier<PropertyPath, IPropertyMapper>>
{
new PropertyNamingApplier(),
};
joinedSubclass = new List<IPatternApplier<Type, IJoinedSubclassAttributesMapper>>
{
new JoinedSubClassKeyColumnApplier()
};
}
The code of ElementNamingApplier is this:
public class ElementNamingApplier : IPatternApplier<MemberInfo, IElementMapper>
{
public void Apply(MemberInfo subject, IElementMapper applyTo)
{
if(subject.Name.Contains("Image"))
{
applyTo.Length(400);
applyTo.NotNullable(true);
applyTo.Unique(true);
}
else if (subject.Name.Contains("Path"))
{
applyTo.Length(400);
applyTo.NotNullable(true);
applyTo.Unique(true);
}
}
public bool Match(MemberInfo subject)
{
return true;
}
}
How can I make this customization using conventions?
Thanks in advance!