MySQL 存储引擎

来源:互联网 发布:短网址源码 编辑:程序博客网 时间:2024/05/29 11:15

存储引擎

MySQL5.5以后默认使用InnoDB存储引擎

1、MyISAM:它不支持事务,也不支持外键,尤其是访问速度快,对事务完整性没有要求或者以SELECT、INSERT为主的应用基本都可以使用这个引擎来创建表。
2、InnoDB:InnoDB存储引擎提供了具有提交、回滚和崩溃恢复能力的事务安全。但是对比MyISAM的存储引擎,InnoDB写的处理效率差一些并且会占用更多的磁盘空间以保留数据和索引。


修改数据库表引擎模式:


ALTER TABLE 表名 ENGINE = InnoDB;


C# Entity Framework 代码中使用事物

1、添加引用System.Transactions
2、using System.Transactions;


public bool CreatePost(Posts data, Dictionary<string, string> dicList){    try    {        using (TransactionScope tran = new TransactionScope())        {            dbContent.PostService.Add(data);            dbContent.SaveChanges();            long id = data.ID;            foreach (var item in dicList)            {                var model = new PostMeta                {                    post_id = id,                    meta_key = item.Key,                    meta_value = item.Value,                };                dbContent.PostMetaService.Add(model);            }            dbContent.SaveChanges();            tran.Complete();            return true;        }    }    catch (Exception ex)    {        Log4netHelper.Tool.LogError("CreatePostNew()", ex.Message);    }    return false;}




0 0
原创粉丝点击