Page 1 of 1

Code First Example using an Int64 Column

Posted: Tue 27 May 2014 22:06
by friday
I'm evaluating dotconnect for sqlite at my company. I'm writing a series of simple test cases in C# using a code first example.

Here's an abbreviated class defining a run table.

Code: Select all

    [Table("Runs")]
    public partial class RunItem 
    {
        [Column("projectName", TypeName = "TEXT")]
        public String ProjectName
        {
             ...
        }

        [Column("id")]
        public Int64 Id 
        {
             ....
        }

        [Key]
        [Index]
        [Column("runDateTime")]
        public Int64 RunDateTime
        {
            .....
        }
    }
I wrote a DbContext as follows:

Code: Select all

    public class RunItemContext : DbContext 
    {
        public DbSet<RunItem> Items { set; get; }

        static RunItemContext()
        {
            System.Data.Entity.Database.SetInitializer<RunItemContext>(new     CreateDatabaseIfNotExists<RunItemContext>());
        }

    }
I also have written a connection factory, not shown, that returns a connection to a local database file. Those three classes plus some configuration in my app.config was all I needed to get started. After this, I was quickly writing test code to operate on the table.

Almost everything seems to work fine. The only problem is that the database created uses Int32 in place of Int64. I've tried a number of options for the TypeName attribute of the column annotation. Outside that, there doesn't seem to be many ways to control the data type without going to Entity Developer. (At least nothing well documented.)

Is there a way to handle this issue without resorting to using Entity Developer?

Re: Code First Example using an Int64 Column

Posted: Thu 29 May 2014 13:36
by Shalex
1. Please execute (new RunItemContext() as IObjectContextAdapter).ObjectContext.CreateDatabaseScript() and specify the SQL script generated for your Runs table.
2. The SQLite engine doesn't make any difference between Int32 and Int64 because they both results in the same affinity type INTEGER. Which database type alias for .NET Int64 do you need and why?

JIC: The default type mapping for the Entity Framework feature in dotConnect for SQLite is available at http://www.devart.com/dotconnect/sqlite ... pping.html.

Re: Code First Example using an Int64 Column

Posted: Thu 29 May 2014 17:42
by friday
Thanks for pointing out (new RunItemContext() as IObjectContextAdapter).ObjectContext.CreateDatabaseScript() to view the script.

I was aware of the data type mapping but was confused seeing an int32 for the value in entity developer. I assumed creating a model from a db file would help me identify my issue and this was a mapping issue. Being new to this (EF6 and SQL), I wasn't expecting the issue to be a value managed by the database.

So, the issue is a user error .