Linq到MySql. DML操作 [英] Linq to MySql. DML operations

查看:90
本文介绍了Linq到MySql. DML操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友...

我是Linq to MySql的新手,并使用Visual Web Developer 2010 Express.

我正在寻找如何与MySql建立MySql数据库连接以及如何进行DML操作.

但是没有弄清楚任何东西并一次又一次地搜索.我也在msdn上阅读,发现它是O/RM.并且需要上课.

我很困惑,为什么我们需要为数据库中存在的每个表创建类.
而EntitiyFramework也与MVC.net中的此非常相似



我正在寻找
1.为什么我们需要为每个表创建类以及如何实现它们.
2.如何使用Linq连接到MySql并直接查询到MySql".

请指导我...

问候
Manish Namdev

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

推荐答案

在下面的链接中查找有关" 对象关系映射的信息".

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

以下是一些与.Net兼容的基于 ORM 的技术/技术.

NHibernate

实体框架

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

报价:

1.为什么我们需要为每个表创建类以及如何实现它们.

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


通过上面的链接,您会发现" ORM "是对象关系映射"数据访问技术.通过这种方式,您可以在对象/列表上执行数据访问操作,而不是直接在数据库表上执行数据访问操作.这就是为什么您需要代表数据库表的类和代表数据库表列的属性/字段的原因.这些类通常称为实体类.在" NHibernate "中,您需要手动编写这些实体类,但是在" Entity Framework "中,它们是自动创建的.

但仍然有一个问题是为什么要对类/对象执行数据访问操作.
答案-这样做的好处很少.
1)这使您的数据访问逻辑/代码RDBMS保持独立.今天您可能正在使用MySQL,而明天您可能会决定使用任何其他RDBMS,在这种情况下,您的数据访问逻辑将保持不变.仅您可能需要在配置文件中进行一些设置更改.
2)在这种使用NUnit或其他单元测试技术进行数据访问的单元测试中,效率更高.


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.

报价:

如何使用Linq连接到MySql并直接查询MySql".

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


您可以在下面参考与此类似的问答"讨论.

Linq to MySql. DML操作


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

Linq to MySql. DML operations




您可以使用mysql连接器代替点.

Mysql连接器

它可以用来查询/连接mysql数据库.您可以使用传统的数据库连接,也可以使用ObjectContext.

关于您的第一个问题为什么我们需要为每个表创建类."
-如果您想使用LINQ to ENTITY,则需要一些中间的EntityManager来管理它.它的POCO方法论可与数据库一起使用.

希望对您有帮助.

谢谢
-阿米特.
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.


这篇关于Linq到MySql. DML操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆