How to use MySql via Linq to SQL
The vs2008 and vs2010 don't support the generation LINQ to SQL business objects from a MySQL database, if you drop a MySql table to a Linq to Sql Class, it will popup a "The selected object(s) use an unsupported data provider" error.
Generation tool DBLinq
DbLinq is a LINQ to SQL data context provider and allows you to create LINQ to SQL business objects from a MySQL database and perform LINQ queries directly against MySQL tables. Utilizing LINQ, it functions in the same way as a typical SQL Server data layer.
a) Download DBLinq from: http://code.google.com/p/dblinq2007/downloads/list
b) Run the LINQ to SQL generation tool DbMetal.exe as follows:
DbMetal.exe -provider=MySql -database:MyDatebase -server:you host computer -user:mysql user -password:you pwd -namespace:mysqllinq -code:mysqllinq.cs -sprocs
Modify the generated file
The generated file can't be use in project right now, we must take some modification on it.
a) Delect all code with #if !MONO_STRICT(take MONO_STRICT as True is ok).
b) Delete the constructors from the DataContext class and add the following constructor:
public MyDBDataContext()
: base(new MySqlConnection(ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString))
{
OnCreated();
}
c) For "Incorrect AutoSync specification for member" error, we should set AutoSync of pk field as AutoSync.OnInsert, the full configuration for pk field:
[Column(Storage = "_userID", Name = "userId", DbType = "int", IsPrimaryKey = true, AutoSync = AutoSync.OnInsert, CanBeNull = false)]
As the .NET compiler will convert the code into a SQL Server syntax statement, run this code under MySql will throw error(Like this issue:http://lists.mysql.com/mysql/215385
相关文档:
Twitter公司一位名叫Ryan King的工程师日前向博客MyNoSQL透露,公司计划从MySQL迁移到Cassandra数据库,因为后者具有更大的弹性、可扩展性和大量的社区网络开源开发人员。
我们有大量的数据,在数据巨大,增长率正在加速的情况下,我们需要一个系统,它可以更为自动化,并高度可靠、可用。Ryan K ......
Accessing Distributed Data with the Federated Storage Engine
http://dev.mysql.com/tech-resources/articles/mysql-federated-storage.html
Federated存储引擎可以使几台数据库逻辑上组成一个数据库,其作用相当于Oracle的数据库链接,通俗地说,即在本地建立远程的数据库表的引用。
Mysql需要5.0以上
(1)查看是 ......
MySQL常用的存储引擎为MyISAM、InnoDB、MEMORY、MERGE,其中InnoDB提供事务安全表,其他存储引擎都是非事务安全表。
MyISAM是MySQL的默认存储引擎。MyISAM不支持事务、也不支持外键,但其访问速度快,对事务完整性没有要求。
InnoDB存储引擎提供了具有提交、回滚和崩溃恢复能力的事务安全。但是比起MyISAM存储引 ......
轉自花開的地方
mysql有一个功能就是可以log下来运行的比较慢的sql语句,默认是没有这个log的,为了开启这个功能,要修改my.cnf或者在mysql启动
的时候加入一些参数。
如果在my.cnf里面修改,需增加如下几行
long_query_time = 1
log-slow-queries
=
log-queries-not-using-indexes
long_query_t ......
做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统。假设 id=1 的这本书库存为 1 ,但是有 2 个人同时来借这本书,此处的逻辑为 :
Select restnum from book where id =1 ;
-- 如果 restnum 大于 0 ,执行 update
Update boo ......