仓储方法:
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是没有[]号的,热心同学帮忙看看,非常感谢!
用的EntityFramework.Extended还是自己写的,还是什么,如果是这个,是因为他不支持mysql。。。
可以自己修改EntityFramework.Extended支持mysql,也可以网上download一个别人写的
我也遇到同样的问题,通过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