.NET, C#, LINQ, SQL and OR-Mapping - I just don't get it :(
I just don't get it, and I'm not even sure if I'm looking in the right direction...
The Problem:
So there is my C# Application. I connect to an online MySQL database via SSH. Now I can run query-stuff on it using the MySQL Connector/.Net driver (http://dev.mysql.com/downloads/connector/net/5.2.html). Everything works fine.
Now I want to some OR-Mapping: I want to run the querys on local entities.
For example: In the online database, there is the table 'order' and it has the attributes 'order_total' and 'order_date'.
No开发者_运维知识库w I run a "SELECT * FROM order"
What's next? How can I turn this result into an entity and then write back the changes after I have modified it? All I could find out until now is, that is has to do someting with LINQ and (maybe) XML. But I just don't get the whole thing :(
I appreciate every hint or maybe a short example :)
Thanks in advance!
What you are thinking of, i think, is Linq to Sql. But that ONLY works for SQL Server.
http://www.mikeborozdin.com/post/LINQ-To-MySQL.aspx
So your only option to build objects out of the data that you get from your MySql server, and then do standard linq to objects to do your mapping.
Hope this helps, Cheers,
Sounds like you want Linq to Entities, which does support databases other than SQL Server. You'd need to locate a MySQL driver - I can see a few when I search online (DevArt, Connector/NET, etc). Haven't tried myself.
There are a lot of ORMs that support Linq queryables. Most of them work with an ADO driver; if there is a flavor of DbProvider that supports your DBMS, and you can specify a ConnectionString that will get you to the DBMS instance, you can use one of these.
Have a look at Fluent NHibernate. IMO it should provide an easy-to-implement, yet extensible mapper that uses your existing domain model, doesn't generate a DTO layer, and best of all doesn't require a lot of XML.
Start by looking at ADO.NET first. It can do what you want.
If you want something more powerful, look at using an ORM like NHibernate or Entity Framework. You don't need Linq, but if you want Linq, you will need to use an ORM. LinqToSql is an ORM that doesn't work with MySQL, so search for "Linq" not "LinqToSql".
There are a ton of samples for how to do this if you know what you are looking for.
精彩评论