Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

byte类型在条件中的解析BUG

Open Beginner friendly
#2,290 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
database

Research direction

Start by searching the FreeSql query expression translation code for handling of Contains over byte arrays or byte-backed enums; the issue does not name a file or test. Reproduce with the supplied SQL Server example and compare ToSql() output with the expected IN lists; done when both enum and byte collections translate to numeric values while the reported scalar comparison and ToList behavior remain correct.

Written by the indexing model from the issue text.

Description

问题描述及重现代码:

byte类型以及基于byte的枚举,在Where条件中涉及枚举数组/集合时,解析错误

    public class MyEntity
    {
        [Column(IsPrimary = true,IsNullable = false,IsIdentity = true)]
        public int Id { get; set; }

        [Column(IsNullable = false, StringLength = 50)]
        public string Name { get; set; }

        [Column(IsNullable = false)]
        public byte Age { get; set; }

        [Column(IsNullable = false, MapType = typeof(byte))]
        public SomeType Type { get; set; }

        [Column(CanUpdate = false, IsNullable = false)]
        public DateTime Created { get; set; }
    }

    public enum SomeType : byte
    {
        A = 1,

        B = 2,

        C = 3,

        D = 4,
    }

    SomeType[] types = [SomeType.A, SomeType.B];
    byte[] ages = [18, 25];
    string aaa = freeSql.Select<MyEntity>()
            .Where(s => s.Id >= 1024)
            .Where(s => types.Contains(s.Type))
            .Where(s => ages.Contains(s.Age))
            .ToSql();

以上示例解析的SQL为:

SELECT a.[Id], a.[Name], a.[Age], a.[Type], a.[Created] 
FROM [MyEntity] a 
WHERE (a.[Id] >= 1024) AND (((a.[Type]) in 0x0102)) AND (((a.[Age]) in 0x1219))

而预期的结果应该为:

SELECT a.[Id], a.[Name], a.[Age], a.[Type], a.[Created] 
FROM [MyEntity] a 
WHERE (a.[Id] >= 1024) AND (((a.[Type]) in(1,2))) AND (((a.[Age]) in (18,25)))

以上在ToList方法下映射表现正常;非数组/集合下正常(如: .Where(s => s.Type == SomeType.C))。

根据文档类型映射和型映射-maptype中,应该允许和支持byte相关使用。

数据库版本

Microsoft SQL Server 2022 (RTM-CU25) (KB5081477) - 16.0.4255.1 (X64)

安装的Nuget包

3.5.311

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

.NET 10.0.13

Dominant language
C#
Stars
4.4k
Forks
911
Avg merge
12h 47m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnetcore/FreeSql

All issues in dotnetcore/FreeSql

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.