I could add a foreign key that doesnot have a primary key.

Issue #112 invalid
Saravana created an issue

No description provided.

Comments (4)

  1. Guillermo Gutiérrez

    Can you provide a description of the issue and the minimal code required to reproduce it?

  2. Uros Rajkovic

    Hi Guille,

    I have the same problem. I have Portable Xamarin project. I am able to insert Users into database without first inserting UserSettings:

    public class UserSettings
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
    
        public int ActiveSearch { get; set; }
    }
    
    public class User
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
    
        public string FirstName { get; set; }
    
        public string LastName { get; set; }
    
        [ForeignKey(typeof(UserSettings))]
        public int UserSettingsId { get; set; }
    }
    
    public async void InitialSeed()
    {
            await _connection.DropTableAsync<UserSettings>();
            await _connection.DropTableAsync<User>();
    
            await _connection.CreateTableAsync<UserSettings>();
            await _connection.CreateTableAsync<User>();
    
            List<User> users = new List<User>();
            users.Add(new User { FirstName = "John", LastName = "Doe", UserSettingsId = 1 });
            users.Add(new User { FirstName = "Jane", LastName = "Doe", UserSettingsId = 2 });
            await _connection.InsertAllAsync(users);
    }
    

    After inserting rows in User table, UserSettings table is empty, while User table contains 2 rows.

  3. Guillermo Gutiérrez

    Hello @urosrajkovic . You haven't defined the relationship and you're not using a SQLite-Extensions method to insert the objects. I'd recommend you to take a look at the documentation and the examples contained in the test project. If you have doubts, feel free to ask in StackOverflow with the sqlite-net-extensions tag.

  4. Log in to comment