参见英文答案 Get Database Table Name from Entity Framework MetaData 22个我正在尝试获取实体的SQL表名称.当我使用MetadataWorkspace查询时,我从对象或存储空间获取大量信息...

参见英文答案 > Get Database Table Name from Entity Framework MetaData 22个
我正在尝试获取实体的SQL表名称.
当我使用MetadataWorkspace查询时,我从对象或存储空间获取大量信息.但架构名称和表名称不存在.
我尝试查询CSpace和SSpace的所有EntityType对象,我可以看到两者都正确列出,但我无法弄清楚如何从CSpace获取SSpace.
所以说我在对象模型中有一个名为User的类型 – 如何在数据库中找到带有模式名称(tkp.User)的表名?
有没有办法做到这一点?
解决方法:
对此没有完美的答案,但这应该有效……
var ssSpaceSet = objectContext.MetadataWorkspace
.GetItems<EntityContainer>(DataSpace.SSpace).First()
.BaseEntitySets
.First(meta => meta.ElementType.Name == "YourEntityName");
如果在调试器中查找,Table属性应该具有实际的表名.
You’d need to use
reflection
in the last part.
Good news is it should transparently work with EF6 too
(as it has a similar base class)
(它与模式类似,也应该在那里 – 这是Db / SQL映射名称,facet等的空间)
看到我的这篇文章有很多细节
Get Model schema to programmatically create database using a provider that doesn’t support CreateDatabase
Get Model schema to programmatically create database using a provider that doesn’t support CreateDatabase
How I can read EF DbContext metadata programmatically?
How check by unit test that properties mark as computed in ORM model?
Programmatic data transformation in EF5 Code First migration
Entity Framework MigrationSqlGenerator for SQLite
http://entityframework.codeplex.com/
Entity Framework – Get Table name from the Entity
ef code first: get entity table name without dataannotations
Get Database Table Name from Entity Framework MetaData
http://www.codeproject.com/Articles/350135/Entity-Framework-Get-mapped-table-name-from-an-ent
本文标题为:c# – 如何以编程方式从实体获取具有模式名称的数据库表名


基础教程推荐
- Unity游戏开发之射击小游戏的实现 2023-05-25
- c#代码生成URL地址的示例 2023-04-10
- C# 模式匹配完全指南 2023-05-25
- Unity实现鼠标或者手指点击模型播放动画 2023-02-06
- C# 判断时间段是否相交的实现方法 2022-11-22
- 基于C#设计一个双色球选号工具 2023-05-26
- .NET 平台负责人 Scott Hunter 专访:.NET Core 3 给 .NET Core 2023-09-27
- C# 实现枚举转列表 2023-03-27
- C#使用GUID(全局统一标识符) 2023-05-31
- C#开发windows服务实现自动从FTP服务器下载文件 2023-01-17