Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > 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.

Not answered 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.

Feed from this thread
  • Christophla avatar

    Posted on Jan 23, 2012 (permalink)

    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?

    Reply

  • Petar Petar admin's avatar

    Posted on Jan 27, 2012 (permalink)

    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

    Reply

  • Christophla avatar

    Posted on Jan 27, 2012 (permalink)

    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.

    Reply

  • Petar Petar admin's avatar

    Posted on Feb 2, 2012 (permalink)

    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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / OpenAccess ORM > General Discussions > 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.
Related resources for "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."

OpenAccess ORM Features  |  Documentation  |  Demos  |  Telerik TV  |  Step-by-step Tutorial   ]