I am following (in a testproject) the instructions to change my project to use fluent instead of the visual designer as its no longer supported.
However after following the steps i get an ORA-00904 error indicating: "ORA-00904: "B"."Id2": invalid ID"
I am guessing it is tripping over a foreign key and it looks quite similair to the thread: http://www.telerik.com/forums/upgrade-adds-a-2-on-some-foreign-keys
Any ideas on how to resolve this?
5 Answers, 1 is accepted
Thank you for contacting us.
Could you provide me with the following additional details:
1. Do you have any inheritance structures in you model (the types of inheritance supported by Data Access are described here)?
2. After which step in the tutorial you receive the error?
3. Could you provide the .rlinq file and the DDL script of the database for a review on our side?
I'm looking forward to hearing from you.
Regards,
Doroteya
Telerik by Progress
Hi and thank you for your reply,
What i did was create a new project and from the VS telerik menu choose: Add Domain Model. Then i would add two classes like: Person and Adres. In Adres i would define a field: PersonId and reference it to the person class.
Then when i access the data all would be fine and i would start converting it using the logic from this post. I would change the mapping type to Fluent; copy and include the specified files, add the fluent assembly's from the package manager.
When i rebuild and access the data i get the oracle error.
I have an example project with a unittest to create/retrieve data. I have included both the project before attempting the conversion to fluent (error free) and after (produces an error when running the test)
Im unfamiliar with the term in your first question so I cant answer that really; however the problem seems to be in the foreign key where a column name is changed to Id2 instead of Id or PersonId.
I get the error after following the steps in the mentioned post. (no compile errors, just a runtime oracle error)
the .rlinq (and everything else) is in the mentioned projects.
Thank you for the additional details.
The reason for the error is that the foreign key constraint between the two classes is missing in the model. The solution is to modify a bit PrepareAdresAssociationConfigurations() using the HasConstraint() method. Without this enhancement Data Access is unable to resolve which of the Adres properties is the foreign key. Thus it defaults to Default Mapping and adds in the metadata model the Id2 column as a foreign key property.
The PrepareAdresAssociationConfigurations() method should look like this:
1.
public
void
PrepareAdresAssociationConfigurations(MappingConfiguration<Adres> configuration)
2.
{
3.
configuration.HasAssociation(x => x.Person)
4.
.HasFieldName(
"_person"
)
5.
.WithOpposite(x => x.Adres)
6.
.HasConstraint((x, y) => x.PersonId == y.Id)
7.
.WithDataAccessKind(DataAccessKind.ReadWrite);
8.
}
The conversion between the .rlinq file and the fluent model did not generated it for two reasons:
- it was not defined in the .rlinq file
- the persistent classes were not mapped to tables in .rlinq file.
I hope this helps.
Regards,
Doroteya
Telerik by Progress
Hello Doroteya,
Thank you for the research and clarification. Adding the HasConstraint indeed fixed the problem for me and the project now runs as expected.
Kind regards,
Roel