QUESTION - FOREIGN KEYS

Issue #81 closed
Former user created an issue

Hello there, im integrating sqlite extensions in a project. I have two questions. When i use the custom attribute [ForeignKey(typeof(Stock))] does this create a SQL CONSTRAINT FOREIGN KEY in the table (eg. FOREIGN KEY(...) REFERENCES Stock(...))?

im using this on an android project and i pulled the database.db file from the simulator and the tables dont have the CONSTRAINT FOREIGN KEY there.

I had another question: To support One to many relations, when it is necessary to use cascade?

Comments (3)

  1. Guillermo Gutiérrez

    does this create a SQL CONSTRAINT FOREIGN KEY in the table?

    No, SQLite-Net Extensions doesn't add foreign key constraints to database as SQLite.Net doesn't support it. In fact, you can skip that attribute and declare the foreign keys in the relationship itself, for example:

    public int OwnerId { get; set; }
    
    [OneToOne("OwnerId")]
    public Person Owner { get; set; }
    

    To support One to many relations, when it is necessary to use cascade?

    Cascade operations are just a utility that is provided to make recursive operations easier, by loading or writing all the model tree at once. If you don't plan to use recursive operations, there's no need to use it.

  2. Log in to comment