Forum Visual Studio

Entity Framework Support?

TonyCaseyTonyCasey IEMember ✭✭

I came across an issue a while back with SQLite and the Entity Framework.

EF creates complex type classes and SQLite does not support any sort of complex type.

I thought I could work around this, but it becomes tedious having to remove the foreign key constraints in my edmx designer view on every EF build.

I really need the complex classes because the same Model is being used in my WebApp. I want to keep the WebApp and the mobile on the same Model (seems a fair expectation).

Anybody come across the same situation?

I came across dotConnect for SQLite but don't want to fork out 150 bucks and waste more time.

Thanks :-)


  • TonyCaseyTonyCasey IEMember ✭✭
    edited May 2013

    I actually sorted this one with a one liner in Sqlite.cs

    When the EF creates the POCO classes it adds the complex types as collections of objects.
    Screenshot (1)

    In SQLite, when creating the table columns, we can simply check if this is a collection and ignore if it is....
    Screenshot (2)

    So to use EF generated POCO classes without editing them, add the code on line 1392 Screenshot (2) and add " && !collection" to line 1394 to SQLite.cs

    1.jpg 51.3K
    2.jpg 49.3K
  • TonyCaseyTonyCasey IEMember ✭✭

    In my previous post, I wasn't actually saving the object so I have spent the past couple of days trying to do it.

    I have managed to get SQLite saving and returning complex types.

    I have to admit, I am no SQLite, or db pro. I used @John 's De/Serializer methods and threw them into the SQLite class and got them working.

    The full file SQLite file is attached (just rename from .txt to .cs).

    When working with EF POCO classes you will need to create another partial class for each object and decorate it with the [Serializeable()] attribute. I also added the PrimaryKey field in mine..

    public partial class Photo
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
Sign In or Register to comment.