首页 新闻 会员 周边

EF Mysql局部更新生成sql不正确

0
[待解决问题]

仓储方法:

public virtual void Update(Expression<Func<T, object>> identityExp, T entity)
        {
            Context.Set<T>().AddOrUpdate(identityExp, entity);
            Save();
        }

调用:

            this.LogRepository.Update(g => g.LogID == 118, u => new Differ.JH.Domain.Models.Glo.LogDomain { IP = "192.168.1.33" });

运行出错:

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[`dfv3`].[`Glo_Log`] SET
[IP] = '192.168.1.33'
FROM [`df' at line 1
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[`dfv3`].[`Glo_Log`] SET
[IP] = '192.168.1.33'
FROM [`df' at line 1

源错误:


行 123:        public virtual void Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity)
行 124:        {
行 125:            Context.Set<T>().Where(where).Update(entity);
行 126:            //var oraQuerys = Filter(where);
行 127:            //if (null != oraQuerys && oraQuerys.Count() > 0)


源文件: e:\公司项目\Differ.JH2016\Differ.JH.Repository\Core\BaseRepository.cs    行: 125 

生成sql语句不正常,mysql是没有[]号的,热心同学帮忙看看,非常感谢!

有容乃大的主页 有容乃大 | 初学一级 | 园豆:5
提问于:2016-05-26 09:23
< >
分享
所有回答(2)
0

用的EntityFramework.Extended还是自己写的,还是什么,如果是这个,是因为他不支持mysql。。。

 

可以自己修改EntityFramework.Extended支持mysql,也可以网上download一个别人写的

czd890 | 园豆:14412 (专家六级) | 2016-05-26 17:11
0

我也遇到同样的问题,通过https://bbs.csdn.net/topics/391025703?page=1 贴中6#flydoos提供的方法成功解决,内容如下:

1.注意:默认情况下,EntityFramework.Extended仅支持SqlServer,所以.Where().Update(),以及.Where().Delete()写法都是不支持的,需要进行下面改造之后才能支持
2.新增:DbContextConfiguration : DbConfiguration
3.调用:在DbContextConfiguration的构造函数调用 EntityFramework.Locator.Current.Register<EntityFramework.Batch.IBatchRunner>(() => new EntityFramework.Batch.MySqlBatchRunner());
4.配置:[DbConfigurationType(typeof(DbContextConfiguration))] public class DbModelContext : DbContext

mytelo | 园豆:202 (菜鸟二级) | 2018-07-31 11:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册