LabelQueryHelper.cs 1.44 KB
using FoodLabeling.Application.Services.DbModels;
using SqlSugar;

namespace FoodLabeling.Application.Helpers;

/// <summary>
/// 标签查询列投影:不含 <c>AppliedRegionType</c>(未迁移时由 <see cref="LabelRegionSchemaHelper"/> 读写)。
/// </summary>
public static class LabelQueryHelper
{
    /// <summary>只读查询入口:强制列投影。</summary>
    public static ISugarQueryable<FlLabelDbEntity> QueryProjected(ISqlSugarClient db) =>
        ProjectListColumns(db.Queryable<FlLabelDbEntity>());

    /// <summary>列表/详情/引用校验等只读场景:SQL 不含 <c>AppliedRegionType</c>。</summary>
    public static ISugarQueryable<FlLabelDbEntity> ProjectListColumns(
        ISugarQueryable<FlLabelDbEntity> query) =>
        query.Select(x => new FlLabelDbEntity
        {
            Id = x.Id,
            IsDeleted = x.IsDeleted,
            CreationTime = x.CreationTime,
            CreatorId = x.CreatorId,
            LastModifierId = x.LastModifierId,
            LastModificationTime = x.LastModificationTime,
            ConcurrencyStamp = x.ConcurrencyStamp,
            LabelCode = x.LabelCode,
            LabelName = x.LabelName,
            TemplateId = x.TemplateId,
            LocationId = x.LocationId,
            LabelCategoryId = x.LabelCategoryId,
            LabelTypeId = x.LabelTypeId,
            LabelType = x.LabelType,
            State = x.State,
            LabelInfoJson = x.LabelInfoJson
        });
}