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.
Related
My current application was built up in SQL Server 2008 server in JAVA with Hibernate and I had used HierarchyId data type for department hierarchy in my database.
I had written SQL queries to deal with HierarchyId datatype. And I also have n-Level of department tree structure.
Now I want to change my Database server from SQL Server 2008 to MySQL as per business requirement.
After feasibility checking I came with the solution that my whole application will migrate to MySQL database server except HierarchyId data type.
So my main challenge is to find alternate solution of HierarchyId data type with the minimal change in coding.
What is the best way to implement department hierarchy in my database?
Thanks...
I faced the similar situation when our team decided to migrate from MS-SQL to MySQL. We resolved the issue using the following steps:
Added a column of type varchar(100) to the same table in MS SQL.
Converted the hierarchyid from hexadecimal value to string using the hierarchyid.ToString() function as saved it in the newly created column using computed column functionality. for eg. 0x58 -> "/1/", 0x7CE0 -> "/3/7/".
The level of the entity is equal to no-of '/''s minus 1.
These columns could be migrated to the MySQL.
The IsDesendantOf() and is method was replaced with LIKE function of string concaenated with '%'.
Thus we got rid of the hierarchyid functionality in MySQL.
Whenever we face such an issue, we just need to ask ourselves, what would we have done if this functionality would not have been provided by the tool we use. We generally end up getting the answer optimally.
Mysql has no equivalent that I'm aware of, but you could store the same data in a varchar.
For operations involving the HierarchyId, you're probably going to have to implement them yourself, probably as either user defined functions or stored procedures.
What sqlserver does looks like the "materialized path" method of storing a hierarchy. One example of that in mysql can be seen at http://www.cloudconnected.fr/2009/05/26/trees-in-sql-an-approach-based-on-materialized-paths-and-normalization-for-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
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.
In MySQL, I need to know which tables depend on other tables. Is it possible to get the relations?
In SQL Server it's possible to see dependent tables. I hope MySQL can do this too.
If it's in pictorical form then that's even better.
Perhaps you want the SHOW CREATE TABLE command?
If there are foreign keys defined, the above command will show you what they are.
Take a look at the information_schema, especially to key_column_usage table.
http://dev.mysql.com/doc/refman/5.0/en/key-column-usage-table.html
Have a look at Database Explorer (object dependency tree) - a unique feature in dbForge Studio for MySQL.
Easily explore object's references and dependants in Database Explorer. Compilation of dependants for debugging is now also available through the object's context menu.
Also, Database Designer can show foreign key relations between tables.
maybe you'd want a graphical front-end to mysql since you're so used to SQL Server. if the foreign keys are defined, it will show up as a link between entities when you reverse engineer the database.
I want to have a field in a Mysql table, which should accept inputs having a fixed size - no more, no less. The input data is a number, but solutions for strings can also be considered, as I have no problem storing this data as varchar like stuff.
To be exact, I want a datatype which will NOT allow me to store a number which is having less than 7 or greater than 7 digits. I dont want to use triggers/stored procedures.
This may be possible with a stored procedure, but I wouldn't do this on database level. Validation like this belongs in your application.
I don't believe there is any way to achieve this in MySQL at present without using triggers or stored procedures. If MySQL supported check constraints then you could do it, but it doesn't, so you can't.
The possible solutions are:
TRIGGER on update/insert.
CHECK constraint, but MySQL parses and promptly discards check constraints.
Application-level validation.
Foreign key to a lookup table containing the 900,000 integers of 7 digits.
The only other suggestion is to migrate to a SQL database that supports CHECK constraints.
Open-source databases that support CHECK constraints include:
PostgreSQL
SQLite
Firebird
Apache Derby
HyperSQL
Every commercial database also supports CHECK constraints.
Basically, MySQL is the only SQL database on the market that doesn't support CHECK constraints!