0

I got a sqlite table in xamarain (native android / pcl):

    [Table("Customer")]
    public class Customer
    {
         [PrimaryKey, AutoIncrement]
         public int Id { get; set; }
         public Address Address{ get; set; }
    }

"Address" represents a second table.

1) Is it possible to automatically create the "Address" Table when I call

connection.CreateTable<CustomerDto>();

because it is it's dependency?

2) Is it possible to use a LINQ expression which automatically maps the correct "Address" to this "Customer?

2 Answers 2

1

In my .NET Standard library I'm using:

  • "sqlite-net": "1.0.8"

  • "sqlite-net-pcl": "1.3.1"

My approach was to create "initial state models" of all the tables, marked as abstract (so there is no risk that somebody could instantiate them), defining only the fields necessary in the database and the primary keys (GUID in my case), used only to create tables at the beginning. Following modification to the data structures always with ALTER instructions. In another namespace a duplication of all the models, this time with getters/setters and other utilities, and I used these as "real models".

For representing linked models I used a field as Id and another one as model (refreshed when necessary):

public int IdAddress { get; set; }
[Ignore]
public Address Address { get; set; }

I don't think sqlite-net can do what you are asking because it's a very lightweight orm, and even if it could I prefer don't automate too much because of my past experiences with Hibernate.

https://github.com/praeclarum/sqlite-net

https://components.xamarin.com/view/sqlite-net

Sign up to request clarification or add additional context in comments.

Comments

0

It sounds like you should look at using Entity Framework because that will allow you to use LINQ with SQLite. The standard library on the web (not Entity framework) is very light and doesn't have much functionality for the ORM like functionality you are looking for.

If you're looking for a more lightweight library, you can use this, but it will not allow you to write LINQ expressions without writing your own ORM: https://github.com/MelbourneDeveloper/SQLite.Net.Standard

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.