This commit is contained in:
2018-10-04 22:30:31 +00:00
parent 7ea5c911aa
commit fc8ea40029
2 changed files with 28 additions and 45 deletions

View File

@@ -28,8 +28,6 @@ Once that is done then can steam ahead on the biz objects but until I have the c
IMMEDIATE ITEMS:
================
- see if any other callers to name fetcher are in tight loops and could benefit from using the new Direct version
- Schema: clean up all the LOOKAT items and verify the indexes are being used
- EventLogProcessor.AddEntry: CHANGE this to save the context itself and then change all callers to handle that (remove save)

View File

@@ -17,58 +17,43 @@ namespace AyaNova.Biz
internal static class BizObjectNameFetcher
{
/*
NOT SURE IF I WILL WANT TO USE THIS OR NOT GOING FORWARD SO KEEPING IT IN PLACE BUT NOT USABLE FOR NOW
*/
internal static string Name(AyaTypeId tid, AyContext ct = null)
{
return Name(tid.ObjectType, tid.ObjectId, ct);
throw new System.NotSupportedException("BizObjectNameFetcher:: Slow version, did you mean to call this one?");
//return Name(tid.ObjectType, tid.ObjectId, ct);
}
//Returns existance status of object type and id specified in database
internal static string Name(AyaType aytype, long id, AyContext ct = null)
{
//new up a context??
if (ct == null)
{
ct = ServiceProviderProvider.DBContext;
}
switch (aytype)
{
case AyaType.User:
return ct.User.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
case AyaType.Widget:
{
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
command.CommandText = $"SELECT m.name FROM awidget AS m WHERE m.id = {id} LIMIT 1";
ct.Database.OpenConnection();
using (var dr = command.ExecuteReader())
{
// do something with result
return dr.Read() ? dr.GetString(0) : "UNKNOWN";
}
}
// var ret = ct.Widget
// .FromSql($"SELECT m.name FROM awidget AS m WHERE m.id = {id} LIMIT 1")
// .FirstOrDefault();
// return ret.Name;
throw new System.NotSupportedException("BizObjectNameFetcher:: Slow version, did you mean to call this one?");
// //new up a context??
// if (ct == null)
// {
// ct = ServiceProviderProvider.DBContext;
// }
// switch (aytype)
// {
// case AyaType.User:
// return ct.User.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
// case AyaType.Widget:
// return ct.Widget.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
}
case AyaType.Tag:
return ct.Tag.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
case AyaType.TagGroup:
return ct.TagGroup.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
case AyaType.FileAttachment:
return ct.FileAttachment.AsNoTracking().Where(m => m.Id == id).Select(m => m.DisplayFileName).FirstOrDefault();
// case AyaType.Tag:
// return ct.Tag.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
// case AyaType.TagGroup:
// return ct.TagGroup.AsNoTracking().Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
// case AyaType.FileAttachment:
// return ct.FileAttachment.AsNoTracking().Where(m => m.Id == id).Select(m => m.DisplayFileName).FirstOrDefault();
default:
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
}
// default:
// throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
// }
}