sqlite-net icon indicating copy to clipboard operation
sqlite-net copied to clipboard

Define relationships

Open cruzzil opened this issue 14 years ago • 12 comments

How can relationships between tables be defined?

cruzzil avatar Aug 04 '12 22:08 cruzzil

I can't find this either???

gbrhaz avatar Aug 06 '12 16:08 gbrhaz

sqlite-net doesn't support this.

What are you trying to do?

class Person {
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Name { get; set; }
}

class Pet {
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public int OwnerId { get; set; } // <-- This is the relationship
    public string Name { get; set; }
}

What do you want to accomplish that this code doesn't already accomplish?

praeclarum avatar Aug 10 '12 18:08 praeclarum

Something like the following:

class Person {
    int id;
    int Name;
    List<Address> Addresses;
}

class Address {
    int id;
    string Street;
    string Country;
}

cruzzil avatar Aug 10 '12 22:08 cruzzil

I need something like that too. Not nested classes, but Lists of strings.

class DictionaryEntry {
    [PrimaryKey, AutoIncrement]
    int ID { get; set; }

    string Word { get; set; }
    string Morphology { get; set; }
    string Etymology { get; set; }
    List<string> Definitions { get; set; }
    List<string> Synonyms { get; set; }
    List<string> Antonyms { get; set; }
}

Is it possible with sqlite-net?

Emasoft avatar Aug 19 '12 11:08 Emasoft

I think that is very critical problem in sqlite-net. I think that shoud be like in BLToolKit.

        [TableName("AccountOwner")]
         class AccountOwner
        {
            [PrimaryKey, Identity]
            public int ID;
            public string Name;
            public string Second_Name;
            public string Description;
        }
        [TableName("MyAccount")]
        class MyAccount
        {
            [PrimaryKey, Identity]
            public int ID;
            [MapField("NAME")]
            public string Name;
            public string Code;
            public string Description;
            [Association(ThisKey = "ID", OtherKey = "ID", CanBeNull = false)]
            public AccountTypes AccountTypes;
            public int OWNER;
            public int Type;
            [Association(ThisKey = "ID", OtherKey = "ID", CanBeNull = false)]
            public AccountOwner AccountOwner;
        }
        [TableName("AccountTypes")]
        class AccountTypes
        {
            [PrimaryKey, Identity] public int ID;
            public string Name;
            public string Description;
        }

shaman4k avatar Sep 01 '12 18:09 shaman4k

Agreed. Relationships between data objects using composition would be really useful.

jmlane avatar Jan 16 '13 16:01 jmlane

@praeclarum @petesmc Anything come of this yet?

I would think anything that considers itself an ORM would be able to handle object relationships, as it is for mapping your objects to an underlying relational database. What this seems to provide is a one to one mapping of a table to an object, and you have to use FK's to link data instead of object references, be that a property containing a single POCO reference or a property containing a collection of POCOs.

Don't get me wrong SQLite-net is useful and servers a purpose but seems a little light for an ORM it would be nice if it had support for object reference relationships and not just FK's that we have to then still join/link in C# after we get the data.

CreepyGnome avatar Jan 19 '13 21:01 CreepyGnome

8 months and still nothing...

louy avatar Mar 28 '13 18:03 louy

The beauty of open source, everyone is welcome to add functionality.

dbeattie71 avatar Mar 29 '13 21:03 dbeattie71

@dbeattie71 thats a crap and copout answer and you know. This is an open issue that @praeclarum has responded to. If he didn't want to address it himself he should close the issue. If you can't contribute constructively to the thread then you really shouldn't post anything.

CreepyGnome avatar Apr 02 '13 21:04 CreepyGnome

Maybe, I'm not so sure. Like most devs I'm sure @praeclarum is busy. Maybe he didn't close it because of the suggestions and activity attached to the request. If there's a feature someone wants, take a stab at it it's a great way to contribute and learn. I apologize if you found my comment non-constructive.

dbeattie71 avatar Apr 02 '13 21:04 dbeattie71

I tried to implement this feature. My pull request. And now i have few commits with implementation of autosetting primary keys to child objects.

daynin avatar Apr 26 '13 23:04 daynin