private async Task <EnumTriplet> GetEnumTripletAsync(Enum enumeration) { EnumTriplet Result = null; SourceTableAttribute att = enumeration.GetType().GetTypeInfo().GetCustomAttributes <SourceTableAttribute>().FirstOrDefault(); Type etype = enumeration.GetType(); if (att != null) { Result = (from t in _EnumLookups where t.EnumerationName == etype.Name && t.KeyName == enumeration.ToString() select t).FirstOrDefault(); if (Result == null) { // Has not already been looked up EnumTriplet Lookup = new EnumTriplet(); var Get = await context.Set <EnumTriplet>() .FromSql($"GetEnumTriplet @p0, @p1", att.Name, enumeration) .AsNoTracking() .ToListAsync(); Result = Get.FirstOrDefault(); //var dr = await context.Database.ExecuteSqlQueryAsync(); //var reader = dr.DbDataReader; //while (reader.Read()) { // Result = new EnumTriplet() { // EnumerationName = etype.Name, // KeyName = reader.GetString(2), // DisplayName = reader.GetString(1), // Value = reader.GetInt32(0), // }; //} if (Result != null) { _EnumLookups.Add(Result); } // if we found it in the database } // if we have not already looked this value up } // if this is a lookup-able Enumeration return(Result); }
private EnumTriplet GetEnumTriplet(Enum enumeration) { EnumTriplet Result = null; SourceTableAttribute att = enumeration.GetType() .GetTypeInfo() .GetCustomAttributes <SourceTableAttribute>() .FirstOrDefault(); Type etype = enumeration.GetType(); if (att != null) { Result = (from t in _EnumLookups where t.EnumerationName == etype.Name && t.KeyName == enumeration.ToString() select t).FirstOrDefault(); if (Result == null) { // Has not already been looked up EnumTriplet Lookup = new EnumTriplet(); var dr = context.Database.ExecuteSqlQuery($"GetEnumTriplet '{att.Name}', '{enumeration}'"); var reader = dr.DbDataReader; while (reader.Read()) { Result = new EnumTriplet() { EnumerationName = etype.Name, KeyName = reader.GetString(2), DisplayName = reader.GetString(1), Value = reader.GetInt32(0), }; } if (Result != null) { _EnumLookups.Add(Result); } // if we found it in the database } // if we have not already looked this value up } // if this is a lookup-able Enumeration return(Result); }