Using GUID for MySQL membership provider user - mysql

I'm using the MySql membership provider with a .NET MVC 4 application and got it all set up as per this tutorial.
The problem is that the provider sets up the mysql_aspnet_users table with the UserID PK as an INT(11), whereas the MSSQL provider uses a UNIQUEIDENTIFIER.
I need to migrate existing users to this database and I would much prefer to keep a Guid as the primary key within the Users and Membership tables.
Is there any way to do this with the MySql membership provider?
Or do I need to write my own MySql membership provider just to use UUIDs as the primary keys?
I've had a look for any documentation or "non-hacky" ways to do this but haven't had any luck so far.

I dont think you can prevent creating a custom membership user class with a custom membership provider. Something like this tutorial http://msdn.microsoft.com/en-us/library/ms366730%28v=VS.85%29.aspx they use GUID's as wel. You need to change the SQL abit so it works with MySQL

You can store a guid as a CHAR(16) binary if you want to make the most optimal use of storage space.
or varchar(36) if its ok .
http://mysqlbackupnet.codeplex.com/wikipage?title=Using%20MySQL%20With%20GUID%20or%20UUID

At work we ended up creating our own MySql membership provider for .NET and it's called Dolphin https://github.com/film-skills/dolphin-net! It also includes a role provider, and allows you to specify in the config whether you use a GUID or an Integer. It's still in very early days and hasn't been tested thouroughly in production though it's a start! Also on NuGet http://www.nuget.org/packages/Dolphin/0.0.2

Related

Primary Key generation MySQL Hibernate

I have an application deployed across 2 instances.
Database: MySQL
ORM: Hibernate
However, I need to implement an Oracle sequence like behaviour. Since MySQL doesn't have any, I simply created a table with an AUTO_INCREMENT and a method to return the value from it. It's thread-safe , so its not a problem when I deploy this application on 1 server. However, I dont think this thread-safe behaviour will hold true across multiple JVMs.
What to do in this case?
It is safe to use across multiple JVMs. MySQL issues each ID once. Use getGeneratedKeys() on a ResultSet to retrieve the generated ID.

How to make portable AND native ID generation in JPA 2 / Hibernate?

I would like to have native and portable id generation on my JPA 2 entities, currently running Hibernate and MySQL
When using #GeneratedValue(strategy=AUTO), hibernate defaults to the "hibernate_sequence" table on MySQL, i would like IDENTITY
If i solve it using #GeneratedValue(strategy=IDENTITY), i loose Oracle/Postgres portability
How can i set Hibernate to use IDENTITY as default for mysql when #GeneratedValue strategy=AUTO?
You can write your own custom generator and maybe invoke a function/stored procedure on your
DB to create the identity you need.
Take a look here , this is a blog with nice example about how to do what I just wrote.
Without code change in Hibernate you cannot affect that. One way around is using different set of mappings (xml instead of annotations) for each database with different id requirements. That is of course quite much to do.
Only truly portable way that works independently from database vendor, is to generate id with TABLE strategy.

MySql Entity Framework Database First - Primary Key = Long?

I am attempting to use the MySql Entity Framework provider for a small project. I've always encountered "quirks" when working with the MySql Connector (the one developed by MySQL, not DevArt).
The latest thing I found was that my entities generated from the database are getting long instead of int for their Id fields even though the type in the database is specified as a SIGNED INTEGER, AUTO INCREMENT, PRIMARY KEY.
The only thing I can think of is that LAST_INSERT_ID() always returns long. Since my entities rely on the database to create the identity value, perhaps MySQL Connector makes the Ids long to accommodate the id retrieval after insert?
The easiest workaround for all the issues I've encountered would be to just use SQL Server. However, the target for this app is shared hosting. Even if you pay for a SQL Server add-on, most shared hosts limit the SQL Server instances to 200MB and only allow 1 or 2 databases. That is just too small in my opinion. The same hosts offer several 1GB MySQL databases for free. If you outgrow that, you probably should have a dedicated box anyway.
MySQL will allways return a 64 bit int (or a BIGINT) instead of a 32 bit int. That's why you're getting a long instead of an int.
See this bugreport: http://bugs.mysql.com/bug.php?id=64084, and the MySQL manual on LAST_INSERT_ID(): http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id.

Bltoolkit - Dealing with identity with multiple db's

How do I deal with identity when I'm supporting multiple db's with Bltoolkit. I know that BL supports InsertWithIdentity call with linq whne doing inserts, but I think it only works with Sql Server and in this instance I don't want to use it in this instance
Is their a better way doing. Pehaps creating some kind of identity map to store the last primary key value for a particular entity stored.
Any advice would be helpful.
Thanks
scope_creep
MySql supports AUTO_INCREMENT, so it's not a problem.
For Oracle there are two ways to implement identity:
Define a trigger.
Use a sequence.

Queries Always Require Table Name to be Preceded by Owner

We recently changed the ownership of all tables from dbo to another existing login(user). Since the change, I must now precede the table name with the name of the new owner whenever I create a query in SQL Server Management Studio (2008), even though the default database is set correctly. Other folks in my group are not required to do this even if we use the same login for SQL Server Management Studio. I'm thinking this must be a personal setting for the Management Studio on my computer but I can't find a setting that would apply to this problem.
Does anyone know of a default setting the would specify the table owner so I don't have to when I create a query?
Thanks for any help you can give,
TJ
You can specify a default schema for a database user not linked to a windows login/group.
Otherwise, it's best practice to qualify objects with schema anyway. This helps execution plan re-use because object references are unambiguous.
Rather then explain here, some references: one, two, three