Code First Example using an Int64 Column
Posted: Tue 27 May 2014 22:06
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.
I wrote a DbContext as follows:
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?
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
{
.....
}
}
Code: Select all
public class RunItemContext : DbContext
{
public DbSet<RunItem> Items { set; get; }
static RunItemContext()
{
System.Data.Entity.Database.SetInitializer<RunItemContext>(new CreateDatabaseIfNotExists<RunItemContext>());
}
}
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?