Field of type "Object" is not created in database with dotConnect Pro 4.6.226

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
bairog
Posts: 120
Joined: Mon 29 Apr 2013 09:05

Field of type "Object" is not created in database with dotConnect Pro 4.6.226

Post by bairog » 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):

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; }
    }
}
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?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Field of type "Object" is not created in database with dotConnect Pro 4.6.226

Post by Shalex » Tue 11 Jun 2013 14:45

Entity Framework supports only primitive types: http://msdn.microsoft.com/en-us/library/ee382832.aspx. From the Entity Framework's point of view, a System.Object is not a primitive type.


Post Reply