ComponentMap (multiple instances of the same component in an entity)

Dmitry's Avatar

Dmitry

16 Mar, 2010 09:40 AM via web

Hello,
I’m trying to map a multiple instances of the same component in an entity, writing something like that:

public class BugDesc
{
    public int Desc1 { get; set; }
    public int Desc2 { get; set; }
    public int Desc3 { get; set; }
}

public class Bug
{
    public Int64 ID { get; set; }
    public BugDesc BugDesc1 { get; set; }
    public BugDesc BugDesc2 { get; set; }
}

public class BugDescMap : ComponentMap<BugDesc>
{
    public BugDescMap()
    {
        Map(x => x.Desc1).Column("DESC1");
        Map(x => x.Desc2).Column("DESC2");
        Map(x => x.Desc3).Column("DESC3");
    }
}

public class BugMap : ClassMap<Bug>
{
    public BugMap()
    {
        Table("BUG");
        Id(x => x.ID).Column("BUG_ID")
            .GeneratedBy.Sequence("BUG_SQ");
        Component(x => x.BugDesc1)
            .ColumnPrefix("FIRST_");
        Component(x => x.BugDesc2)
            .ColumnPrefix("SECOND_");
    }
}

But it doesn't work, I have an exception during the saving of my entity: "Invalid index 4 for this OracleParameterCollection with Count=4" (I think, this is because of multiple presence of property in the result mapping). When I try to load already existing entity it generates such SQL: "Select BUG_ID, SECOND_FIRST_DESC1, SECOND_FIRST_DESC2, SECOND_FIRST_DESC3 from BUG" and of course can’t find such fields in the table. When I use one instance of component it works fine.

  1. Support Staff 2 Posted by James Gregory on 17 Mar, 2010 11:41 AM

    James Gregory's Avatar

    That's pretty weird. I'll investigate this later on today.

  2. 3 Posted by Dmitry on 26 Mar, 2010 11:03 AM

    Dmitry's Avatar

    Hello, is where are something new in this question?

  3. 4 Posted by Dmitry on 04 May, 2010 10:38 AM

    Dmitry's Avatar

    Hello! Sorry, for my importunity, did you investigate this problem?

  4. 5 Posted by Franck on 11 May, 2010 04:18 PM

    Franck's Avatar

    Hi all,
    I'm getting the same issue with build 1.0.0.650.

  5. 6 Posted by Franck on 12 May, 2010 07:56 AM

    Franck's Avatar
    public class Store {
        public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual Address Address1 { get; set; }
        public virtual Address Address2 { get; set; }
     }
    public class StoreMap : ClassMap<Store> {
        public StoreMap() {
            Id(x => x.Id);
            Map(x => x.Name);
                        Component(x => x.Address1).ColumnPrefix("ADDR1_");
                        Component(x => x.Address2).ColumnPrefix("ADDR2_");
    }
        public AddressMap() {
            Map(x => x.Number, "NUMBER");
            Map(x => x.Street, "STREET");
            Map(x => x.City, "CITY");
            Map(x => x.PostCode, "POSTCODE");
        }
    

    Produce the following SQL

    CREATE TABLE "Store" (Id integer, ADDR2_ADDR1_NUMBER INTEGER, ADDR2_ADDR1_STREET TEXT, ADDR2_ADDR1_CITY TEXT, ADDR2_ADDR1_POSTCODE TEXT, Name TEXT, primary key (Id));

    Is there a workaround ?

  6. 7 Posted by Dmitry on 12 May, 2010 11:54 AM

    Dmitry's Avatar

    You can do somthing like this:

    public class AddressMap
    {
        public static Action<ComponentPart<Address>> WithColumnPrefix(String columnPrefix)
        {
            return a =>
            {
                a.Map(x => x.Number).Column(columnPrefix + "NUMBER")
                    .Not.Nullable();
                a.Map(x => x.Street).Column(columnPrefix + "STREET")
                    .Not.Nullable();
                a.Map(x => x.City).Column(columnPrefix + "CITY")
                    .Not.Nullable();
                a.Map(x => x.PostCode).Column(columnPrefix + "POSTCODE")
                    .Not.Nullable();
            };
        }
    }
    

    public class StoreMap : ClassMap {

    public StoreMap() {
        Id(x => x.Id);
        Map(x => x.Name);
        Component(x => x.Address1, AddressMap.WithColumnPrefix("ADDR1_"));
        Component(x => x.Address2, AddressMap.WithColumnPrefix("ADDR2_"));
    

    }

    But of couse it will be great to use standart functionality for such things and I hope this issue will be fixed in the nearest future.

  7. 8 Posted by Franck on 12 May, 2010 01:12 PM

    Franck's Avatar

    Thanks Dmitry
    I Hope it will be fixed soon because ComponentMap is a great feature

  8. Support Staff 9 Posted by James Gregory on 15 May, 2010 10:17 PM

    James Gregory's Avatar

    FYI, this issue only presents itself when you specify the column names explicitly; if you don't do that, it should work fine.

    I'm investigating a fix right now.

  9. Support Staff 10 Posted by James Gregory on 15 May, 2010 11:00 PM

    James Gregory's Avatar

    I've committed a fix for this (revision e8f13b0). Feedback would be appreciated.

  10. 11 Posted by Dmitry on 17 May, 2010 11:29 AM

    Dmitry's Avatar

    Does the latest build (#677) contain this changes? The question is because of I get it but the problem remained.

  11. Support Staff 12 Posted by James Gregory on 17 May, 2010 01:32 PM

    James Gregory's Avatar

    667 should fix the issue. I was able to create the problem, then fixed it. Could you provide us with an updated example using the latest binaries?

  12. 13 Posted by Franck on 17 May, 2010 02:00 PM

    Franck's Avatar

    I've replaced with version 677 and it works for me.
    Thanks for the fix
    James you make a great job for the community

  13. 14 Posted by Dmitry on 17 May, 2010 03:46 PM

    Dmitry's Avatar

    I'm sorry, it was my mistake.
    Thanks a lot for the fix.

  14. Support Staff 15 Posted by James Gregory on 17 May, 2010 04:02 PM

    James Gregory's Avatar

    No problem, glad it worked.

  15. James Gregory resolved this discussion on 17 May, 2010 04:02 PM.

Comments are currently closed for this discussion. You can start a new one.