DbSet table name

后端 未结 6 1211
广开言路
广开言路 2020-12-03 17:14

To get database table name on Entity framework 4.0 I do:

ObjectSetInstance.EntitySet.ToString()

Is there a way to do this on Entity Framewo

6条回答
  •  孤街浪徒
    2020-12-03 18:12

    You can try something like this.

    private string GetTableName(Type type)
    {
      var tableAttribute = type.GetCustomAttributes(false).OfType().FirstOrDefault();
      return tableAttribute == null ? type.Name : tableAttribute.Name;
    }
    

    You can call this string like this.

    var tableName = GetTableName(entityType.FirstOrDefault());
    

    Please see the below link for further info. Link

提交回复
热议问题