- edited description
[Foreign Key] created but there is no relation in the Database
I have 2 tables with OneToMany relationship:
[Table("Account")]
public class Account
{
[PrimaryKey, AutoIncrement, NotNull]
public int Id { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.CascadeDelete)]
public List<Check> Checks { get; set; }
}
[Table("Check")]
public class Check
{
[PrimaryKey, AutoIncrement, NotNull]
public int Id { get; set; }
[ForeignKey(typeof(Account))]
public int AccountId { get; set; }
}
After creation, there is a "Check_AccountId" index in the database but as you see there is no relation between the tables:
On the other hand, I can't make the Foreign Key works (created) without an error.
What happens?
Comments (6)
-
reporter -
Hi John,
As stated in the project description, SQLite-Net Extensions doesn't perform any change in your database schema. So there's no explicit relation created in the database.
On the other hand, can you explain in detail the error that you are getting?
-
reporter Thanks for the reply,
There is no error. But if there is no change in the schema and no foreign key created, so how it works?
How can I rely the database?
-
Foreign keys are found by searching for properties with
ForeignKey
attribute on runtime using reflection. You have access to the full source code, all the reflection-related code is located in ReflectionExtensions class if you wonder how it works. Take a look atGetForeignKeyProperty
method for more details. -
reporter Thank you for your information.
So as far as I understand, all things handled in the code at runtime and there is no exact relation in the database.
-
- changed status to closed
Exactly. That's how it works.
Closing the issue.
- Log in to comment