admin 管理员组文章数量: 1086019
I have a function I call in OnModelCreating
lots of times, I'm trying to see if I can just have this happen automatically.
The WithProjection function is being called for properties that are a class type that inherits from a particular class, so it's easy enough to distinguish them, so I already have a list of my desired properties. Instead of manually defining these in my application's OnModelCreating
, I was hoping to just be lazy:
var models = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes())
.Where(t => t.IsSubclassOf(typeof(ModelBase)));
foreach (var model in models)
{
var modelProperties = model.GetProperties();
foreach (var modelProperty in modelProperties)
{
Type modelPropertyType = modelProperty.PropertyType;
//Some irrelevant filtering logic here
builder.Entity<modelPropertyType>() //doesn't work because modelPropertyType is a var
.WithProjection() // <-- my custom function
}
}
Builder has an alternate Entity
function that takes a type as a parameter, but it returns a generic EntityTypeBuilder
object, not a typed one, which tracks but means my custom function doesn't work as it's attached to the typed object.
I think my only option to make this work is to recreate my entire custom function to operate on the untyped EntityTypeBuilder, but before I do, I'm asking you.
Is there a way to get a typed EntityTypeBuilder here?
本文标签: Possible to use a variable entity type or workaroundStack Overflow
版权声明:本文标题:Possible to use a variable entity type or workaround? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744011802a2518291.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论