Fluent API Error : "Columns can only be shared between a simple and a reference field. Usually, the reference field is the master and the simple field is the slave.

4 posts, 0 answers
  1. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 23 Jan 2012 Link to this post

    In converting our existing domain model over to the fluent mapping, we get the error, "Columns can only be shared between a simple and a reference field. Usually, the reference field is the master and the simple field is the slave."

    We have a class that references itself multiple times.

    i.e.

    Product.SupercededBy {get;set}
    Product.Parent {get;set}
    Product.Supplements {get;set}

    each returns a Product

    mapping.HasAssociation(p => p.Supplements).HasConstraint((p, c) => p.SupplementsId == c.Id);
    mapping.HasAssociation(p => p.SupercededBy).HasConstraint((p, c) => p.SupercededById == c.Id);
    mapping.HasAssociation(p => p.Parent).HasConstraint((p, c) => p.ParentId == c.Id);

    each has a unique foreign key in the database

    This relationship worked just fine using the domain reverse-mapping tools... so, in theory, it should be reproducible using the only the Fluent API.

    P.S. What is a simple field? and what is a reference field?
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 27 Jan 2012 Link to this post

    Hi Christophla,

     I have created the same setup on my side and everything seems to work as expected. Here is the test model I have used:

    public int ID { get; set; }
           public string ProductName { get; set; }
           public decimal Price { get; set; }
     
           public Product Product1 { get; set; }
           public Product Product2 { get; set; }
           public Product Product3 { get; set; }
           public int ID1 { get; set; }
           public int ID2 { get; set; }
           public int ID3 { get; set; }
    And here is the actual mapping:
    protected override IList<MappingConfiguration> PrepareMapping()
            {
                List<MappingConfiguration> configurations = new List<MappingConfiguration>();
     
                MappingConfiguration<Product> productConfiguration = new MappingConfiguration<Product>();
                productConfiguration.MapType().ToTable("Products");
                productConfiguration.HasProperty(x => x.ID).IsIdentity(KeyGenerator.Autoinc);
                productConfiguration.HasAssociation(p => p.Product1).HasConstraint((p, c) => p.ID1 == c.ID);
                productConfiguration.HasAssociation(p => p.Product2).HasConstraint((p, c) => p.ID2 == c.ID);
                productConfiguration.HasAssociation(p => p.Product3).HasConstraint((p, c) => p.ID3 == c.ID);
     
                configurations.Add(productConfiguration);
     
                return configurations;
            }
    Please do let me know if I am missing something in my configuration that is there in yours.

    Kind regards,
    Petar
    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

  3. DevCraft banner
  4. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 27 Jan 2012 Link to this post

    Yours differs in that you map to three unique foreign id's (id1, id2, id3).

    Try mapping the three products to the same foreign key (id1) and you will most likely get the same error.
  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 02 Feb 2012 Link to this post

    Hi Christophla,

     In your example you have used the same structure as well. You are mapping to SupplementsId , SupercededById  and  ParentId which seem to be three different fields. Does that scenario work for you or that is the one that is throwing the exception?

    All the best,
    Petar
    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

Back to Top