FreeSql icon indicating copy to clipboard operation
FreeSql copied to clipboard

FreeSql 中,使用 Firebird 数据库生成的sql 语句,所有的位运算都是错的

Open uin84101100 opened this issue 1 month ago • 1 comments

问题描述及重现代码:


// c# code

 public enum CliState
 {
   None = 0,
   Del = 1024
}

public class MCliFile
{
  [Column(IsPrimary = true, StringLength = 16)]
  public string efNo { get; set; }

  public short efState { get; set; }

  [Column(StringLength = 20)]
  public string efName { get; set; }
}

string sql = fsql.Select<MCliFile>().Where(c => (int)(c.cfState & (int)CliState.Del) == (int)CliState.Del).ToSql();
// 此时生成的 sql 语言为:
// SELECT a."cfNo", a."cfState", a."cfName" FROM "client_file" a WHERE ((a."cfState" & 1024) = 1024)
// 但是 Firebird 是不支持 &、|、^、~ 这几个 常用的 运算符的,这玩意要用 BIN_AND、BIN_OR、BIN_XOR、BIN_NOT
// 就边最最基本的 移位 <<、>> 都得用 BIN_SHL、BIN_SHR 来写
// 相对的 Bitwise Functions 请参见
//  https://www.firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref50/fblangref50-functions-bitwise.html

数据库版本

我用的 Firebird 的5.0.3,但我看手册 Firebird 全系列 应该都有这个问题

安装的Nuget包

FreeSql 所有的包(包括最新的 3.5.303)都有这个问题

.net framework/. net core? 及具体版本

uin84101100 avatar Nov 22 '25 14:11 uin84101100

#1413

这个问题存在,我以为改正了

忘记在 FirebirdUtils.cs 重写代码了

麻烦 override 一下提交 PR,谢谢

2881099 avatar Nov 23 '25 15:11 2881099