Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends...

I'm novice to Linq to MySql and using Visual Web Developer 2010 express.

I am looking how can I make MySql Database connection with MySql and how to make DML operations.

But not getting anything clear and searching again and again. I read on msdn also and found it is O/RM. and need to make classes.

I'm confused why we need to create classes for every table that exists in the database.
And EntitiyFramework is also much similar to this in MVC.net



I'm seeking for
1. Why we need to create classes for every table and how to implement them.
2. "How to make connection to MySql using Linq and query directly to MySql".

Please guide me...

Regards
Manish Namdev
Posted

Have a look at below link for information on "Object-relational mapping".

http://en.wikipedia.org/wiki/Object-relational_mapping

Below are some of the ORM based Technologies/Techniques compatible with .Net.

NHibernate

Entity Framework

Quote:
1. Why we need to create classes for every table and how to implement them.

From above links you will get an idea that "ORM" is "Object-relational mapping" Data-Access technique. In this you perform your Data-Access operations on Objects/Lists instead of directly on Database Tables. This is the reason you require Classes which represent your Database Tables, and Properties/Fields which represents your DB Table Columns. These Classes generally called as Entity Classes. In "NHibernate" you require to write these Entity Classes manually, but in "Entity Framework" they are created automatically.

But still Question is Why to perform Data-Access operations on Classes/Objects.
Answer - Few benefits of this.
1) This keeps your Data-Access logic/code RDBMS independent. Today you might be using MySQL and tomorrow you may decide to use any other RDBMS, in this case your Data-Access logic will remain unchanged. Only you may require to do some setting changes in your configuration file.
2) In this Unit-Testing of your Data-Access using NUnit or other Unit-Testing Technology is more efficient.

Quote:
"How to make connection to MySql using Linq and query directly to MySql".

You may refer below similar Question-Answer discussion for this.

Linq to MySql. DML operations
 
Share this answer
 
Comments
Manish Kumar Namdev 30-Nov-11 2:45am    
Hello RaisKazi, Many thanks to you.
I think this is what I was looking you explained the things thank you.
I will go through the links you provided.

And further doubts I will catch you.
RaisKazi 30-Nov-11 2:48am    
Glad to know this information is useful to you :). You may accept this answer by "Accept Answer"(green) button. Cheers.
member60 30-Nov-11 3:39am    
my 5!
RaisKazi 30-Nov-11 3:53am    
Thank you.
Hi,

you can use mysql connector for dot not.

Mysql connector

it can be used to query/connect with mysql database. you can use traditional database connection or you can also use ObjectContext for that.

about your first question "why we need to create class for every table."
- if you want to use LINQ to ENTITY you need some intermediate EntityManager to manage it. its POCO methodology to work with database.

hope this will help you.

thanks
- amit.
 
Share this answer
 
Comments
Manish Kumar Namdev 30-Nov-11 1:31am    
Hello amit
many thanks to reply.
Well I have a mysql database connector, and using MySqlConnection class to make connections.
what I was thinking that "Linq to MySql" will create a connection it self and would have similar classes as MySql have.

And for my first question --- Does this POCO methodology is efficient to use? how is it better than the normal way we use i.e. simply making connection and using MySqlDataAdapter or MySqlCommand to query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900