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
相关文档:
这时间在安装PHPBB的论坛,发现一个问题,那就是输入用户名跟密码后,点击安装,总是报了以下的错误:
程序代码
ORA-28008: invalid old password
Cause: old password supplied is wrong; Hence user cannot be authenticated using old password
Action: Supply the correct old password for authenticatio ......
http://book.51cto.com/art/200803/68118.htm
摘要:《深入浅出MySQL——数据库开发、优化与管理维护》从数据库的基础、开发、优化、管理4方面对MySQL进行了详细的介绍,其中每一部分都独立成篇,每一篇又包括多个章节。本书面向实用,内容覆盖广泛,讲解由浅入深,适合于各个层次的读者。
第20章 锁问题
锁是 ......
Twitter公司一位名叫Ryan King的工程师日前向博客MyNoSQL透露,公司计划从MySQL迁移到Cassandra数据库,因为后者具有更大的弹性、可扩展性和大量的社区网络开源开发人员。
我们有大量的数据,在数据巨大,增长率正在加速的情况下,我们需要一个系统,它可以更为自动化,并高度可靠、可用。Ryan K ......
mysql锁机制
mysql中对表级的存储引擎来说是释放死锁的,避免死锁可以这样做到:在任何查询之前先请求锁,并且按照请求的顺序锁表。
Mysql中用于write(写)的表锁的实现机制如下:
如果表没有加锁,那么就加一个写锁。否则的话,将请求放到写锁队列中。
mysql中用于read(读)的表锁的实现机制如下:
如果表没有加锁,那么 ......
做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统。假设 id=1 的这本书库存为 1 ,但是有 2 个人同时来借这本书,此处的逻辑为 :
Select restnum from book where id =1 ;
-- 如果 restnum 大于 0 ,执行 update
Update boo ......