Field of type "Object" is not created in database with dotConnect Pro 4.6.226
Posted: Tue 11 Jun 2013 04:57
Hello.
I'm using dotConnect for SQLite 4.6.226 Pro with Entity Framework Code-First (EF version is 5.0).
Code sample to run "as-is" (add reference to EntityFramework.dll (I use assembly v4.4.20627.0 for .NET 4.0), System.Data.Entity and System.ComponentModel.DataAnnotations to run this code):
The result of executing this code is database with two fields - Id and Code. No Value field is present in database.
If you try to enumerate Categories after that you receive one SystemTypeCategoryDTO object with Id = 1, Index = 0 and Value = null.
If you delete Index field from code above - the "empty insert statement" exception is raised while execution.
Looks like Object fields are not mapped to any database types at all.
Is that a bug? Or how can I solve this problem?
I'm using dotConnect for SQLite 4.6.226 Pro with Entity Framework Code-First (EF version is 5.0).
Code sample to run "as-is" (add reference to EntityFramework.dll (I use assembly v4.4.20627.0 for .NET 4.0), System.Data.Entity and System.ComponentModel.DataAnnotations to run this code):
Code: Select all
using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace EF_CodeFirst_SQLite
{
class Program
{
static void Main(string[] args)
{
Database.DefaultConnectionFactory = new SQLiteConnectionFactory();
var context = new BloggingContext("Data Source=D:\\DBSys.db; FailIfMissing=false;");
var connection = ((IObjectContextAdapter) context).ObjectContext.Connection;
connection.Open();
using (DbTransaction transaction = connection.BeginTransaction())
{
context.Categories.Add(new SystemTypeCategoryDTO() { Id = 1, Value = "123" });
context.SaveChanges();
transaction.Commit();
}
}
}
public class SQLiteConnectionFactory : IDbConnectionFactory
{
private const string invariantName = "Devart.Data.SQLite";
public DbConnection CreateConnection(string ConnectionString)
{
if (String.IsNullOrEmpty(ConnectionString))
throw new ArgumentNullException("ConnectionString");
DbProviderFactory sqliteProviderFactory = DbProviderFactories.GetFactory(invariantName);
if (sqliteProviderFactory == null)
throw new InvalidOperationException(String.Format("The '{0}' provider is not registered on the local machine.", invariantName));
DbConnection connection = sqliteProviderFactory.CreateConnection();
connection.ConnectionString = ConnectionString;
return connection;
}
}
public class SystemTypeCategoryDTO
{
[Key]
public int Id { get; set; }
public int Index{ get; set; }
public Object Value{ get; set; }
}
class BloggingContext : DbContext
{
public BloggingContext(string connString)
: base(connString)
{
}
public DbSet<SystemTypeCategoryDTO> Categories { get; set; }
}
}
If you try to enumerate Categories after that you receive one SystemTypeCategoryDTO object with Id = 1, Index = 0 and Value = null.
If you delete Index field from code above - the "empty insert statement" exception is raised while execution.
Looks like Object fields are not mapped to any database types at all.
Is that a bug? Or how can I solve this problem?