In some reason, I need to use SQL in EFCore, and I will use table name of mapped entity. How can I get it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Using the Microsoft.EntityFrameworkCore.Relational package:
var mapping = dbContext.Model.FindEntityType(typeof(YourEntity)).Relational();
var schema = mapping.Schema;
var tableName = mapping.TableName;
This assumes that dbContext
is a instance of class that inherits from DbContext
and that you have YourEntity
configured there.