This is a migrated thread and some comments may be shown as answers.

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.

3 Answers 42 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christophla
Top achievements
Rank 1
Christophla asked on 23 Jan 2012, 09:05 PM
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?

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 27 Jan 2012, 05:47 PM
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

0
Christophla
Top achievements
Rank 1
answered on 27 Jan 2012, 08:11 PM
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.
0
PetarP
Telerik team
answered on 02 Feb 2012, 09:15 AM
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

Tags
General Discussions
Asked by
Christophla
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Christophla
Top achievements
Rank 1
Share this question
or