praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.05k stars 1.42k forks source link

Define relationships #80

Open petesmc opened 12 years ago

petesmc commented 12 years ago

How can relationships between tables be defined?

gbrhaz commented 12 years ago

I can't find this either???

praeclarum commented 12 years ago

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?

petesmc commented 12 years ago

Something like the following:

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

class Address {
    int id;
    string Street;
    string Country;
}
Emasoft commented 12 years ago

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?

shaman4k commented 12 years ago

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;
        }
jmlane commented 11 years ago

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

CreepyGnome commented 11 years ago

@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.

louy commented 11 years ago

8 months and still nothing...

dbeattie71 commented 11 years ago

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

CreepyGnome commented 11 years ago

@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.

dbeattie71 commented 11 years ago

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.

daynin commented 11 years ago

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