timabell / ef-enum-to-lookup

Generates lookup tables from enum references in Microsoft Entity Framework 6.1
https://www.nuget.org/packages/ef-enum-to-lookup
69 stars 29 forks source link

Exception on SQL Server Compact 4.0 #30

Open feinstein opened 9 years ago

feinstein commented 9 years ago

I get an exception saying : "Invalid set option. [ Set option = nocount ]" when I try to run the enumToLookup.Apply(context);

captura_de_tela_051015_064339_pm

sveinhelge commented 9 years ago

SQL CE only accept one SQL statement for each ExecuteSqlCommand. So we would need to loop a set of statements(One call to ExecuteSqlCommand for every line/statement). SQL CE does not support nocount, xact_abort, begin, end.

We would need to create a new SqlCompactServerHandler that implements IDbHandler. But since SQL CE only support one statement for each call we need to change the apply method. May be having an option that says call execute SQL command for each line.

I would change this from bug to improvement

timabell commented 9 years ago

I got as far as putting all the SQL behind an interface so we can swap out implementations for different RDBMs but I haven't had time to work out what we're connected to.

sveinhelge commented 9 years ago

You could use:

context.Database.Connection is SqlCeConnection;

If true it's an SQL CE.

Or get the provider name: context.Database.Connection.ToString();

sveinhelge commented 9 years ago

In the custom schema branch I added an new extension for DbContext.

https://github.com/sveinhelge/ef-enum-to-lookup/blob/custom-schema/EfEnumToLookup/LookupGenerator/Extensions/ContextExtensions.cs

We could add these methods to that extension.

public static string GetProviderName(this DbContext context) { return context.Database.Connection.ToString(); }

public static string GetServerVersion(this DbContext context) { return context.Database.Connection.ServerVersion; }

public static bool IsSqlCe(this DbContext context) { return context.Database.Connection is SqlCeConnection; }

This way we get the name of the provider, database version and if this is an SQL CE.

Database version could be used to decide if we should use table variable instead of #temp-table like mentioned in issue #23