Customize collection of strings

17 views
Skip to first unread message

Plácido Monteiro Dinelli Bisneto

unread,
Aug 12, 2011, 10:09:31 AM8/12/11
to codec...@googlegroups.com
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.Column(subject.ReflectedType.Name + "ImagePath");
applyTo.Length(400);
applyTo.NotNullable(true);
applyTo.Unique(true);
}
else if (subject.Name.Contains("Path"))
{
applyTo.Column(subject.ReflectedType.Name + "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!

Fabio Maulo

unread,
Aug 13, 2011, 8:41:12 AM8/13/11
to codec...@googlegroups.com
perhaps a bug.

2011/8/12 Plácido Monteiro Dinelli Bisneto <cid...@live.com>



--
Fabio Maulo

Plácido Monteiro Dinelli Bisneto

unread,
Aug 16, 2011, 9:03:14 AM8/16/11
to codec...@googlegroups.com
I'm planing to spent some time with this but I'm not familiarized with git, so.. If I find the problem and fix it, how can I send back to you?

Plácido Monteiro Dinelli Bisneto

unread,
Aug 16, 2011, 9:12:47 AM8/16/11
to codec...@googlegroups.com
Sorry... not git, Mercurial... I was reading a piece of code in  github and wrote git by mistake.

Fabio Maulo

unread,
Aug 16, 2011, 11:22:35 AM8/16/11
to codec...@googlegroups.com
Pull-request o patch

2011/8/16 Plácido Monteiro Dinelli Bisneto <cid...@live.com>

Sorry... not git, Mercurial... I was reading a piece of code in  github and wrote git by mistake.



--
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages