Search found 37 matches

by pleb
Thu 11 Feb 2010 14:35
Forum: dotConnect for SQLite
Topic: NHibernate support
Replies: 2
Views: 15958

Do not worry (not that you would), but I've worked it out.

The hbm2ddl.keywords error was from me being a little lazy and using the built-in sqlite dialect support.

changed

Code: Select all

        public override ISet GetReservedWords()
        {
            var result = new HashedSet();

            DataTable dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);
            
            foreach (DataRow row in dtReservedWords.Rows)
            {
                result.Add(row["name"].ToString());
            }

            return result;
        }
to (notice the row[...])

Code: Select all

		public virtual ISet GetReservedWords()
		{
			var result = new HashedSet();
			DataTable dtReservedWords = connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);
			foreach (DataRow row in dtReservedWords.Rows)
			{
				result.Add(row["ReservedWord"].ToString());
			}
			return result;
		}

As for the other error is was simple the way the built-in dialect handled the limit clause.. I won't go into too much detail as I've included the fully code below.


And here's the working version....

Code: Select all


// Fluent configuration helper (99% borrowed from fluent core)

namespace AI.Core.Persistence.Providers.NHibernate.Configuration.Fluent.Database
{
    public class DevartSqlite : PersistenceConfiguration
    {
        public static DevartSqlite Standard
        {
            get { return new DevartSqlite(); }
        }

        public DevartSqlite()
        {
            Driver();
            Dialect();
            Raw("query.substitutions", "true=1;false=0");  
        }

        public DevartSqlite InMemory()
        {
            Raw("connection.release_mode", "on_close");
            return ConnectionString(c => c.Is("Data Source=:memory:;Version=3;"));
            
        }

        public DevartSqlite UsingFile(string fileName)
        {
            return ConnectionString(c => c.Is(string.Format("Data Source={0};Version=3;", fileName)));
        }

        public DevartSqlite UsingFileWithPassword(string fileName, string password)
        {
            return ConnectionString(c => c.Is(string.Format("Data Source={0};Version=3;Password={1};", fileName, password)));
        }        
    }
}

// driver (99% borrowed from core)

namespace AI.Core.Persistence.Providers.NHibernate.Driver
{
    public class DevartSqlite : ReflectionBasedDriver
    {
        public DevartSqlite()
            : base(
                "Devart.Data.SQLite",
                "Devart.Data.SQLite.SQLiteConnection",
                "Devart.Data.SQLite.SQLiteCommand")
        {
        }

        public override bool UseNamedPrefixInSql
        {
            get { return true; }
        }

        public override bool UseNamedPrefixInParameter
        {
            get { return true; }
        }

        public override string NamedPrefix
        {
            get { return ":"; }
        }

        public override bool SupportsMultipleOpenReaders
        {
            get { return false; }
        }
		
        public override bool SupportsMultipleQueries
        {
            get { return true; }
        }
    }
}

// dialect (99% borrowed from core)

namespace AI.Core.Persistence.Providers.NHibernate.Dialect
{
    public class DevartSqlite : global::NHibernate.Dialect.Dialect
    {
        public DevartSqlite()
        {
            RegisterColumnType(DbType.Binary, "BLOB");
            RegisterColumnType(DbType.Byte, "INTEGER");
            RegisterColumnType(DbType.Int16, "INTEGER");
            RegisterColumnType(DbType.Int32, "INTEGER");
            RegisterColumnType(DbType.Int64, "INTEGER");
            RegisterColumnType(DbType.SByte, "INTEGER");
            RegisterColumnType(DbType.UInt16, "INTEGER");
            RegisterColumnType(DbType.UInt32, "INTEGER");
            RegisterColumnType(DbType.UInt64, "INTEGER");
            RegisterColumnType(DbType.Currency, "NUMERIC");
            RegisterColumnType(DbType.Decimal, "NUMERIC");
            RegisterColumnType(DbType.Double, "NUMERIC");
            RegisterColumnType(DbType.Single, "NUMERIC");
            RegisterColumnType(DbType.VarNumeric, "NUMERIC");
            RegisterColumnType(DbType.AnsiString, "TEXT");
            RegisterColumnType(DbType.String, "TEXT");
            RegisterColumnType(DbType.AnsiStringFixedLength, "TEXT");
            RegisterColumnType(DbType.StringFixedLength, "TEXT");

            RegisterColumnType(DbType.Date, "DATETIME");
            RegisterColumnType(DbType.DateTime, "DATETIME");
            RegisterColumnType(DbType.Time, "DATETIME");
            RegisterColumnType(DbType.Boolean, "INTEGER");
            RegisterColumnType(DbType.Guid, "UNIQUEIDENTIFIER");

            RegisterFunction("second", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%S\", ?1)"));
            RegisterFunction("minute", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%M\", ?1)"));
            RegisterFunction("hour", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%H\", ?1)"));
            RegisterFunction("day", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%d\", ?1)"));
            RegisterFunction("month", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%m\", ?1)"));
            RegisterFunction("year", new SQLFunctionTemplate(NHibernateUtil.Int32, "strftime(\"%Y\", ?1)"));
            RegisterFunction("substring", new StandardSQLFunction("substr", NHibernateUtil.String));
        }

        public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
        {
            return new SqLiteDataBaseMetaData(connection);
        }

        public override string AddColumnString
        {
            get
            {
                return "add column";
            }
        }

        public override string IdentitySelectString
        {
            get 
            { 
                return "select last_insert_rowid()"; 
            }
        }

        public override SqlString AppendIdentitySelectToInsert(SqlString insertSql)
        {
            return insertSql.Append("; " + IdentitySelectString);
        }

        public override bool SupportsInsertSelectIdentity
        {
            get
            { 
                return true; 
            }
        }

        public override bool HasAlterTable
        {
            get 
            { 
                return false; 
            }
        }

        public override bool DropConstraints
        {
            get 
            { 
                return false; 
            }
        }

        public override string ForUpdateString
        {
            get 
            { 
                return string.Empty; 
            }
        }

        public override bool SupportsSubSelects
        {
            get 
            { 
                return true; 
            }
        }

        public override bool SupportsIfExistsBeforeTableName
        {
            get 
            { 
                return true; 
            }
        }

        public override bool HasDataTypeInIdentityColumn
        {
            get 
            { 
                return false; 
            }
        }

        public override bool SupportsIdentityColumns
        {
            get 
            { 
                return true; 
            }
        }

        public override string IdentityColumnString
        {
            get
            {
                // identity columns in sqlite are marked as being integer primary key
                // the primary key part will be put in at the end of the create table,
                // so just the integer part is needed here
                return "integer";
            }
        }

        public override string Qualify(string catalog, string schema, string table)
        {
            StringBuilder qualifiedName = new StringBuilder();
            bool quoted = false;

            if (!string.IsNullOrEmpty(catalog))
            {
                if (catalog.StartsWith(OpenQuote.ToString()))
                {
                    catalog = catalog.Substring(1, catalog.Length - 1);
                    quoted = true;
                }
                
                if (catalog.EndsWith(CloseQuote.ToString()))
                {
                    catalog = catalog.Substring(0, catalog.Length - 1);
                    quoted = true;
                }

                qualifiedName.Append(catalog).Append(StringHelper.Underscore);
            }

            if (!string.IsNullOrEmpty(schema))
            {
                if (schema.StartsWith(OpenQuote.ToString()))
                {
                    schema = schema.Substring(1, schema.Length - 1);
                    quoted = true;
                }

                if (schema.EndsWith(CloseQuote.ToString()))
                {
                    schema = schema.Substring(0, schema.Length - 1);
                    quoted = true;
                }
                qualifiedName.Append(schema).Append(StringHelper.Underscore);
            }

            if (table.StartsWith(OpenQuote.ToString()))
            {
                table = table.Substring(1, table.Length - 1);
                quoted = true;
            }
            if (table.EndsWith(CloseQuote.ToString()))
            {
                table = table.Substring(0, table.Length - 1);
                quoted = true;
            }

            string name = qualifiedName.Append(table).ToString();
            
            if (quoted)
            {
                return OpenQuote + name + CloseQuote;
            }

            return name;

        }

        public override string NoColumnsInsertString
        {
            get 
            { 
                return "DEFAULT VALUES"; 
            }
        }

        public override bool SupportsLimit
        {
            get 
            { 
                return true; 
            }
        }

        public override bool BindLimitParametersInReverseOrder
        {
            get
            {
                return true;
            }
        }

        public override bool SupportsVariableLimit
        {
            get
            {
                return true;
            }
        }
        
        public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
        {
            SqlStringBuilder pagingBuilder = new SqlStringBuilder();
            pagingBuilder.Add(querySqlString);
            pagingBuilder.Add(" limit ");
            pagingBuilder.Add(Parameter.Placeholder);

            if (offset > 0)
            {
                pagingBuilder.Add(" offset ");
                pagingBuilder.Add(Parameter.Placeholder);
            }

            return pagingBuilder.ToSqlString();
        }
    }
}

// dialect schema (99% borrowed from core) (not all - this replaces SQLiteDataBaseMetaData in the core)

namespace AI.Core.Persistence.Providers.NHibernate.Dialect.Schema 
{
    public class SqLiteDataBaseMetaData : AbstractDataBaseSchema
    {
        private new DbConnection Connection { get; set; }

        public SqLiteDataBaseMetaData(DbConnection connection) 
            : base(connection) 
        {
            Connection = connection;
        }

        public override ITableMetadata GetTableMetadata(DataRow rs, bool extras)
        {
            return new SQLiteTableMetaData(rs, this, extras);
        }

        public override ISet GetReservedWords()
        {
            var result = new HashedSet();

            DataTable dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);
            
            foreach (DataRow row in dtReservedWords.Rows)
            {
                result.Add(row["name"].ToString());
            }

            return result;
        }
    }
}

Hope this helps ;)

Pleb

Edited to fix bug with "InMemory" fluent helper.
Edited to fix bug with fluent helper.
by pleb
Thu 11 Feb 2010 10:54
Forum: dotConnect for SQLite
Topic: NHibernate support
Replies: 2
Views: 15958

NHibernate support

Hello devart,

I was wondering if there was plans to support nhibernate?

I've written my own classes to support this, but I'm having a few issues.

Namely the first is that I have to turn off hbm2ddl.keywords.

Similar issue is explained here http://orbitalcoder.wordpress.com/2009/ ... rvedwords/.

And the second is I'm also getting
NHibernate.ADOException : could not execute query
[ SELECT this_.ModelID as ModelID20_0_, this_.Version as Version20_0_, this_.Descriptor as Descriptor20_0_, this_.CreatedBy as CreatedBy20_0_, this_.CreatedOn as CreatedOn20_0_, this_.ModifiedBy as ModifiedBy20_0_, this_.ModifiedOn as ModifiedOn20_0_, this_.IsDeleted as IsDeleted20_0_, this_.AssociationOneId as Associat9_20_0_, this_.AssociationTwoId as Associa10_20_0_ FROM Models this_ WHERE this_.Descriptor in (@p0, @p1, @p2, @p3, @p4, @p5) limit 2 offset 2 ]
Positional parameters: #0>a #1>b #2>c #3>d #4>e #5>f
[SQL: SELECT this_.ModelID as ModelID20_0_, this_.Version as Version20_0_, this_.Descriptor as Descriptor20_0_, this_.CreatedBy as CreatedBy20_0_, this_.CreatedOn as CreatedOn20_0_, this_.ModifiedBy as ModifiedBy20_0_, this_.ModifiedOn as ModifiedOn20_0_, this_.IsDeleted as IsDeleted20_0_, this_.AssociationOneId as Associat9_20_0_, this_.AssociationTwoId as Associa10_20_0_ FROM Models this_ WHERE this_.Descriptor in (@p0, @p1, @p2, @p3, @p4, @p5) limit 2 offset 2]
----> Devart.Data.SQLite.SQLiteException : 2nd parameter to sqlite3_bind() out of range
bind or column index out of range
which I see was questioned here http://www.devart.com/forums/viewtopic. ... ight=range, but answered by email.

Here's my code to support nhibernate. (Note I'm using the default sqlite dialect and configuration via fluent)

Fluent support

Code: Select all

   public class DevartSqliteConfiguration : PersistenceConfiguration
    {
       public static DevartSqliteConfiguration Standard
        {
            get { return new DevartSqliteConfiguration(); }
        }

       public DevartSqliteConfiguration()
        {
            Driver();
            Dialect();
            Raw("query.substitutions", "true=1;false=0");  
        }

       public DevartSqliteConfiguration InMemory()
        {
            Raw("connection.release_mode", "on_close");
            return ConnectionString(c => c
                .Is("Data Source=:memory:;Version=3;New=True;"));
            
        }

       public DevartSqliteConfiguration UsingFile(string fileName)
        {
            return ConnectionString(c => c
                .Is(string.Format("Data Source={0};Version=3;New=True;", fileName)));
        }

       public DevartSqliteConfiguration UsingFileWithPassword(string fileName, string password)
        {
            return ConnectionString(c => c
                .Is(string.Format("Data Source={0};Version=3;New=True;Password={1};", fileName, password)));
        }        
    }
Nhibernate support

Code: Select all

    public class DevartSqliteDriver : ReflectionBasedDriver
	{
        public DevartSqliteDriver()
            : base(
            "Devart.Data.SQLite",
            "Devart.Data.SQLite.SQLiteConnection",
            "Devart.Data.SQLite.SQLiteCommand")
		{
		}

		public override bool UseNamedPrefixInSql
		{
			get { return true; }
		}

		public override bool UseNamedPrefixInParameter
		{
			get { return true; }
		}

		public override string NamedPrefix
		{
			get { return "@"; }
		}

		public override bool SupportsMultipleOpenReaders
		{
			get { return false; }
		}
		
		public override bool SupportsMultipleQueries
		{
			get { return true; }
		}
	}
[/url]
by pleb
Mon 27 Apr 2009 22:36
Forum: Entity Framework support
Topic: Linq OrderByDescending and First problem
Replies: 2
Views: 3598

Thanks AndreyR, this has cleared it up for me :D
by pleb
Mon 27 Apr 2009 04:04
Forum: Entity Framework support
Topic: Linq OrderByDescending and First problem
Replies: 2
Views: 3598

Linq OrderByDescending and First problem

Hello,

I'm not sure if this is a bug or if it's not possible.

Code: Select all

CREATE TABLE  `RealGamesFeedData`.`ProductHistoryLogs` (
  `ProductHistoryLogId` char(36) NOT NULL,
  `ProductId` char(36) NOT NULL,
  `Action` enum('Updated','Created','Deleted') NOT NULL,
  `Entry` datetime NOT NULL,
  PRIMARY KEY  (`ProductHistoryLogId`),
  KEY `IN_ProductHistoryLogs_Entry` (`Entry`),
  KEY `IN_ProductHistoryLogs_Action` (`Action`),
  KEY `FK_ProductHistoryLogs_Product` (`ProductId`),
  CONSTRAINT `FK_ProductHistoryLogs_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I'm trying to get the first result of the rows return when I order the table by entryDate desc and where product id = some product id.

After playing around I found that this works

Code: Select all

context.ProductHistoryLogSet.Where(p => p.Products.ProductId == "d27248b8-604a-bd93-0ed6-81c3033da219").OrderByDescending(log => log.Entry).First()
And this does not (which I realise now the first is a better way to do it)

Code: Select all

context.ProductHistoryLogSet.OrderByDescending(log => log.Entry).First(p => p.Products.ProductId == "d27248b8-604a-bd93-0ed6-81c3033da219")
When I load DbMonitor I can see that in the latter the order by is being left out.

Should these both not return the same result?

Thanks

Pleb.
by pleb
Tue 30 Dec 2008 00:47
Forum: dotConnect for MySQL
Topic: Deployment using ClickOnce
Replies: 2
Views: 2233

Hi Jasonlv,

I've used the devart connector in a click once deployment without much trouble. You'll need to make sure the devart assembly files are included with your deployment.

You can do this by - adjusting the "Application Files" in the project properties or by changing the assembly references to copy local.

Hope this helps,

Pleb
by pleb
Wed 05 Nov 2008 00:42
Forum: dotConnect for MySQL
Topic: Entity Framework Deployment Problem -Unable to find provider
Replies: 5
Views: 16493

Thank you for the hints.

I added the following to the app.config file (Machine config is a little to low level for one application)

Code: Select all

	
		
			
		
	
and included the CoreLab.MySql.Entity assembly in the deployment.
by pleb
Tue 04 Nov 2008 01:00
Forum: dotConnect for MySQL
Topic: Entity Framework Deployment Problem -Unable to find provider
Replies: 5
Views: 16493

Entity Framework Deployment Problem -Unable to find provider

Hi There,

I've built a little feed down loader which parses and saves the data in a database using the Entity Framework and MySQL provider.

I have some command lines args which force the creation and deletion of the database. These use raw ado.net and the MySQL driver. They work fine. :shock:

When I go to import the feed data I get this message
"The specified store provider cannot be found in the configuration, or is not valid."


However, when I run the command line program on my development box it works fine. :roll:

Initially I thought it'd be a dll missing from the deployment but CoreLab.Data and CoreLab.MySql are there.

Does anyone have any ideas, that I could try?

Pleb
by pleb
Thu 21 Aug 2008 23:20
Forum: dotConnect for MySQL
Topic: Error with Build 4.70.31, EDM, and VS 2008 SP1
Replies: 9
Views: 5192

Thanks Shalex, though your PR people beat your too it. I got an email yesterday saying it was available...

Anyway thank you as it seems to be working very well. :)
by pleb
Fri 15 Aug 2008 06:07
Forum: dotConnect for MySQL
Topic: Error with Build 4.70.31, EDM, and VS 2008 SP1
Replies: 9
Views: 5192

Hi adambsn,

The EDM drive support is in beta. You probably shouldn't be using it production. Though I too have broken this rule! :lol:

From previous experience I'd say they'll release the updated drive in around a week or two.

Probably your only choice would be to roll back to vs 2008 sp1-beta. I mean if this is very important, then the roll back is the way to go. Ah the joy of VS and it's very quick install process :roll:

Pleb
by pleb
Wed 13 Aug 2008 06:14
Forum: dotConnect for MySQL
Topic: Error with Build 4.70.31, EDM, and VS 2008 SP1
Replies: 9
Views: 5192

Once again Andrey thanks for the update. You guys ROCK!
by pleb
Wed 13 Aug 2008 05:45
Forum: dotConnect for MySQL
Topic: Error with Build 4.70.31, EDM, and VS 2008 SP1
Replies: 9
Views: 5192

Ok I've found the problem...

http://blogs.msdn.com/adonet/archive/20 ... anges.aspx

Any chance someone from Devart could post a when the next build supporting sp1 will be out?
by pleb
Wed 13 Aug 2008 04:50
Forum: dotConnect for MySQL
Topic: Error with Build 4.70.31, EDM, and VS 2008 SP1
Replies: 9
Views: 5192

Error with Build 4.70.31, EDM, and VS 2008 SP1

I have installed VS 2008 SP1 (not beta) and now have a problem with the EDM designer. I wonder if anyone knows away around it?

The MsSQL driver works, so I've narrowed it down to the 4.70.31 Devart driver. I probably guess MS made a breaking change between beta and release.

To reproduce try to update and existing EDM or create a new EDM. The error should be thrown in the reverse engineering database wizard section.

The error I get is
An error occured while connecting to the database. The database might be unavailable. An exception of type 'System.Data.EntityCommandComplilationException' occurred. The error message is: 'An error occurred while preparing the command definition. See the inner exception for details. The inner exception caught was of type 'System.MethodAccessException', with this error message: 'System.Data.Common.CommandTrees.Db.CommandTree.Validate()'.'.
by pleb
Thu 07 Aug 2008 11:46
Forum: dotConnect for MySQL
Topic: EDM .net GUID
Replies: 18
Views: 8721

WOW it's sounds great. Thanks for even considering it, and more importantly thanks for accepting it. :wink:
by pleb
Wed 30 Jul 2008 00:06
Forum: dotConnect for MySQL
Topic: EDM .net GUID
Replies: 18
Views: 8721

Hi Andrey,

I agree that this is rather sophisticated, though I had a little chuckle when when I thought about the implementation of an ado data provider and it's sophistication. Isn't that what you deal with everyday? :P

Here's me thinking out loudly,

The configuration form would reside in VS, and the mappings would store locally on the developers machine.

How do you get these mappings to work with the mysql ado.net driver and entity driver?

A custom configuration section in the app.config or web.config file? The configuration form could write out this section for the developer. A developer could write out there own configuration.

Maybe an interface or abstract class could be used. The configuration form writes out the necessary classes or a developer creates them manually. The objects are loaded into the driver, and when the driver is working out the type, you could use these objects as call backs which would give the implementation to handle the type and conversion to and from?

Ok now I see why it's sophisticated :D

Hmmm

What are you guys thinking?

Pleb
by pleb
Mon 28 Jul 2008 03:20
Forum: dotConnect for MySQL
Topic: EDM .net GUID
Replies: 18
Views: 8721

First thanks for the support of Guids, as this will make switching between the corelabs MySQL entity driver and any other entity driver which supports Guids easier.

I'd just like to raise the topic of "Is there a better way"

What are you thoughts of a global configuration form where you could set conditions that would apply to type selection when reverse engineering the database - table structure.

For example

"MySQL Type char, length 36, .net type Guid"

or

"MySQL Type tiny int, length 1, .net type Bool"

or

"MySQL Type enum, .net type String"

or

"MySQL Type set, .net type String"

This way the responsibility would be handed off to the developer for mapping non straight forwards types.

Pleb