refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.
This commit is contained in:
25
HRD.WebApi/Helpers/AttributeReader.cs
Normal file
25
HRD.WebApi/Helpers/AttributeReader.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
|
||||
namespace HRD.WebApi.Helpers
|
||||
{
|
||||
public static class AttributeReader
|
||||
{
|
||||
//Get DB Table Name
|
||||
public static string GetTableName<T>(DbContext context) where T : class
|
||||
{
|
||||
// We need dbcontext to access the models
|
||||
var models = context.Model;
|
||||
|
||||
// Get all the entity types information
|
||||
var entityTypes = models.GetEntityTypes();
|
||||
|
||||
// T is Name of class
|
||||
var entityTypeOfT = entityTypes.First(t => t.ClrType == typeof(T));
|
||||
|
||||
var tableNameAnnotation = entityTypeOfT.GetAnnotation("Relational:TableName");
|
||||
var TableName = tableNameAnnotation.Value.ToString();
|
||||
return TableName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user