How do I convert LINQ to SQL for MySQL?

7

I'm trying to remove the use of SQL statements from within the system (to make it flexible on the database that will be used), I use statements Insert , Update and Delete via stored procedure (for performance and for flexibility), but I still use SQL statements for the queries because they are turned into stored procedures I'm going to have to create multiple procedures for each table of the system.

So how can I convert any LINQ statement in a SQL to MySQL?

    
asked by anonymous 28.01.2015 / 14:57

2 answers

5

By the comments you have to understand (I think) that you want to stop using SQL to use LINQ.

In addition to everything Vinícius said, you should not do this if you want the possibility of using several different databases. Perhaps the most noticeable limitation of LINQ To SQL is that it can not work with multiple banks.

If this is your intention you should either create your own mechanism or use some ready one that abstracts the differences between the various banks.

I will not say that I recommend but you should take a look at the Entity Framework , this is ORM which is recommended by Microsoft in such cases. In the Wikipedia page there is a list of other options like NHibernate which still has reasonable use as well.

It's not easy to learn to use them but it should give you the results you expect.

I do not know these products enough to tell you how easy it is to work with stored procedures the way you intend using these technologies.

With EF you can use LINQ but in the LINQ To Entities model.

If you prefer something simpler and you can continue dealing with SQL you can take a look at Dapper . In general I prefer simpler ways. But of course in this case you have to know how to work with the various banks without causing confusion. I particularly find it easier to do this way but most programmers find it easier to leave a framework ready to deal with it.

I reinforce the idea already reported by others that stored procedure is not a good idea for what you want. Much less will bring the benefits you are reporting you will have. I would say it will probably bring the opposite result in some situations.

    
28.01.2015 / 16:29
6

Stored procedure does not have significant performance gain for CRUD operations, unless you are doing data aggregations and complex manipulations that would involve many "come and go" between your application and the DB.

Store procedures also do not increase flexibility, since each RDBMS has different syntax, causing the rewrite to times up to the total of the procedure.

As you have not posted any code, I recommend that you read Microsoft's own beginner's guide on the subject:

Beginner's Guide to LINQ to SQL

Editing

To use LINQ with MySql, I believe your only option is the LinqConnector package, which even supports other RDBMS beyond MySQL. It is available in NuGet for installation or at the address:

LinqConnect Express

    
28.01.2015 / 15:24