41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Microsoft.EntityFrameworkCore;
|
|
namespace AyaNova.Biz
|
|
{
|
|
|
|
//Turn a type and ID into a displayable name
|
|
//Used by search and eventlog processor
|
|
internal static class BizObjectNameFetcherDirect
|
|
{
|
|
internal static string Name(AyaType ayaType, long id, System.Data.Common.DbCommand cmd)
|
|
{
|
|
try
|
|
{
|
|
|
|
cmd.CommandText = $"select PUBLIC.AYGETNAME({id}, {(int)ayaType}) as m";
|
|
// cmd.CommandText = $"SELECT m.{COLUMN} FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1";
|
|
using (var dr = cmd.ExecuteReader())
|
|
return dr.Read() ? dr.GetString(0) : "-";
|
|
}
|
|
catch
|
|
{
|
|
((ILogger)AyaNova.Util.ApplicationLogging.CreateLogger("BizObjectNameFetcherDirect")).LogError($"### Error fetching for type {ayaType}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
//warning: use the above in a loop, not this one
|
|
internal static string Name(AyaType ayaType, long id, AyaNova.Models.AyContext ct)
|
|
{
|
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
ct.Database.OpenConnection();
|
|
return Name(ayaType, id, command);
|
|
|
|
}
|
|
}
|
|
|
|
}//eoc
|
|
}//eons
|
|
|