I have added a column for UserType on user's table.
I have referenced User table on Unit table.
I have added a LookUpScript on UnitsRow as shown below:
[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 is of type enum, as shown below:
[EnumKey("SmartAttendance.UserTypes")]
public enum UserTypes
{
[Description("Admin")] Admin = 1,
[Description("Lecturer")] Lecturer = 2,
[Description("Student")] Student = 3
}
However, when I go to add a new unit/edit an existing one the dropdown is empty. I have 3 users in the database and one user is of type UserTypes.Lecturer
Please advise what I am missing.
Create a new lookupclass for lecture( admin , student)
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
}
}
}