Skip to content

Easy way to retrieve and use lookups/dropdown across your application.

Notifications You must be signed in to change notification settings

yido/easy-lookup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Easy-Lookup-Management

Easy way to retrieve and use lookups/dropdown across your application.

    Bind<Models.UserType>().To<Enums.UserType>();
    Map<Enums.UserType>().SetSchemaName("Account").SetTableName("UserType").SetCodeColumn("Type").SetNameColumn("Type").SetIdColumn("ID");

Lets cache our lookups on the first load.

 public ICollection<LookUpModel> GetLookups<TEnum>() where TEnum : IConvertible
    {
        var enumDescriptor = BindingManager.GetEnumDescriptor<TEnum>();

        if (_lookUpModels == null) CacheAllLookups(); 

    }

Lets Build Simple plain SQL Query by using EnumDescriptors

           private void CacheAllLookups()
      {
          var query = "";
          foreach (var enumDiscriptor in BindingManager.EnumDescriptors.Values)
          {
              query += String.Format(" Select '{3}' SchemaName,'{4}' TableName , {0} ID,{1} Name,{2} Code from {3}.{4} ",
                  enumDiscriptor.ID,
                  enumDiscriptor.Name,
                  enumDiscriptor.Code,
                  enumDiscriptor.SchemaName,
                  enumDiscriptor.TableName);
              query += (BindingManager.EnumDescriptors.Values.Last() == enumDiscriptor) ? "" : "UNION";
          }

          var data = Database.SqlQuery<LookUpModel>(query);  
          _lookUpModels = data.ToList();
      }

Set your constant values for latter use.

     BLL.UserType.Constants.ADMIN = Program.LookupKernel.GetLookup(Enums.UserType.Admin).ID;      

There you go!

About

Easy way to retrieve and use lookups/dropdown across your application.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages