I'm fairly new to SQL and SQLite. What I'm trying to do is: I have three different classes, which are related. Obj1, Obj2 and Obj3. The relation is that Obj1 one has one or more Obj2 and Obj2 has one or more Obj3. The way I organized my models to save in the database is the following:
class Obj1
{
int Id
string Name
}
class Obj2
{
int Id
int Obj1Id
string Name
}
class Obj3
{
int Id
int Obj2Id
string Name
}
In my UI, the user can create the instances as they want and the classes are organized as the following in my ViewModel (for binding purposes):
class Obj1
{
int Id
string Name
List<Obj2> objs2
}
class Obj2
{
int Id
List<Obj3> objs3
string Name
}
class Obj3
{
int Id
string Name
}
By the time I want to save the objects in database, I don't have any ids to relate to. I don't want to save objects and then query the Id that SQLite automatically gave to it back. How could I do this in a single sql stament? Is that possible?
In another queries, I'm using something like:
public static async Task<bool> SaveClient(Client client)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
await cnn.ExecuteAsync("insert into Client (Name, CreationDate, ServerPath) values (@Name, @CreationDate, @ServerPath)", client);
}
}