【发布时间】:2018-02-14 23:36:41
【问题描述】:
我正在使用 Entity Framework 6 和 ASP.NET,我遇到了这个问题:
假设我在 2 个类模型 A、B 上配置了这 2 个实体映射: 类 A { 字符串属性 1 { 获取;设置 }, 字符串属性 2 {get;放} } B 类 { 字符串属性 1 { 获取;设置 }, 字符串属性 2 {get;设置}}
public class AConfiguration : EntityTypeConfiguration<A> {
ToTable("TableA");
Property( x => x.propperty1 ).maxLength(10).HasColumnName("Column1");
Property( x => x.property2 ).maxLength(10).HasColumnName("Column2");
}
public class BConfiguration : EntityTypeConfiguration<B> {
ToTable("TableB");
Property( x => x.propperty1 ).maxLength(10).HasColumnName("Column1");
Property( x => x.property2 ).maxLength(10).HasColumnName("Column2");
}
假设我已经为我的项目完成了 EF 的配置,并且对 DB 的读写工作正常。
现在我的问题是:有没有办法以字典格式检索我们上面配置的所有属性? 例如:
//This would return a dictionary that looks somehow like this:
/* {
"TableA": {
property1: {
maxLength: 10
}
property2: {
maxLength: 10
}
},
"TableB": {
property1: {
maxLength: 10
}
property2: {
maxLength: 10
}
}
}
*/
// I want to look for some method similar to this
var allEntityTypeConfiguration = entityFrameworkConfig.getAllEntityTypeConfiguration()
毕竟,我想要检索的是 EntityTypeConfiguration 中定义的所有属性的列表及其配置(例如:maxLength 10,或类似的东西)
我用谷歌搜索了一段时间,但仍然没有找到 EF 提供的任何方法。如果可能,是否有解决方法?
【问题讨论】:
-
嘿@Son Do,当你说所有属性意味着......你想要检索所有 表名 和 列名 ** 与 **数据类型 哪些存在于 EF 中,对吗?
-
嗨,你说得对
-
请查看以下解决方案,如果您觉得它有用,请接受它作为答案
标签: asp.net asp.net-mvc entity-framework