ASP.NET EF Core 5 获取数据库表名、字段名

本文发布于 4 年前,部分内容可能已经失去参考价值。

获取表名:

using Microsoft.EntityFrameworkCore;
var entityType = _context.Model.FindEntityType(typeof(表实体));
var tableName = entityType.GetTableName();

获取字段名:

using Microsoft.EntityFrameworkCore;
var entityType = _context.Model.FindEntityType(typeof(表实体));
var dic = new Dictionary<string, string>();
foreach (var p in entityType.GetProperties())
{
    dic.Add(p.Name, p.GetColumnBaseName());
}


xoyozo 3 年前
转载请注明出处
云服务器 精选特惠
可能相关的内容