使用 Serenity.is temp 为用户 table 过滤 LookUpEditor

Filter LookUpEditor for user table using Serenity.is temp

我在用户 table.

上添加了一列 UserType

我在单元 table 上引用了用户 table。

我在 UnitsRow 上添加了一个 LookUpScript,如下所示:

[DisplayName("Lecturer"), NotNull, ForeignKey("[dbo].[Users]", "UserId"), LeftJoin("jLecturer"), TextualField("Lecturer")]
        [LookupEditor(typeof(UserRow), FilterField = "UserType", FilterValue = UserTypes.Lecturer)]
        public Int32? LecturerId
        {
            get { return Fields.LecturerId[this]; }
            set { Fields.LecturerId[this] = value; }
        }

UserType是枚举类型,如下图:

[EnumKey("SmartAttendance.UserTypes")]
public enum UserTypes
{
    [Description("Admin")] Admin = 1,
    [Description("Lecturer")] Lecturer = 2,
    [Description("Student")] Student = 3
}

但是,当我去添加一个新的 unit/edit 一个现有的时,下拉列表是空的。我在数据库中有 3 个用户,其中一个用户的类型为 UserTypes.Lecturer

请告知我缺少什么。

为讲座(管理员、学生)创建一个新的查找类

namespace my.abc
{
    using Serenity.ComponentModel;
    using Serenity.Data;
    using Serenity.Web;
    using System.Linq;
    using BaseRow = Entities.UserRow;
    [LookupScript]
    public sealed class LecturerRow: RowLookupScript<BaseRow>
    {
        private static BaseRow.RowFields fld => BaseRow.Fields;
        public LecturerRow()
        {
            IdField = fld.Id.PropertyName;
            TextField = fld.Userdetails.PropertyName;
        }
        protected override void PrepareQuery(SqlQuery query)
        {
            
            query
                .Select(fld.Id)
                .Select(fld.user, fld.username , fld.UserTypes)
                .Where(fld.UserTypes== 2);
        }
        protected override void ApplyOrder(SqlQuery query)
        {
            query
                .OrderBy(fld.username );enter code here
        }
    }
}

恕我直言,将 [LookupInclude] 属性添加到 UserRow.cs 中的 UserType 字段应该可以做到。

HTH 汉内斯