为什么这一行通用代码适用于一个实体对象而不适用于另一个实体对象?

发布于 2024-12-24 18:31:59 字数 1220 浏览 2 评论 0原文

我在使用 http://www.codeproject.com/ 的通用存储库时遇到一些问题KB/architecture/RepositoryUnit.aspx

在“FetchEntityName”中有一行代码,对于某些实体似乎会崩溃,而对于其他一些实体则不会,它们都以同样的方式变得艰难!

我将范围缩小到这个返回 false 的手表表达式。 (我将 18 作为索引器,因为它是似乎运行不佳的实体(组)之一)

typeof(IQueryable<>).MakeGenericType(typeof(T)).IsAssignableFrom(this.ObjectContext.GetType().GetProperties()[18].PropertyType)

返回 false! 左侧:

typeof(IQueryable<>).MakeGenericType(typeof(T))   

在手表中返回:

{Name = "IQueryable`1" FullName = "System.Linq.IQueryable`1[[Domain.Groep, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}    System.Type {System.RuntimeType}

右侧:

this.ObjectContext.GetType().GetProperties()[18].PropertyType

在手表中返回:

{Name = "ObjectSet`1" FullName = "System.Data.Objects.ObjectSet`1[[Contacts.Groep, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}    System.Type {System.RuntimeType}

英文?

为什么对于我的 EDMX 中的某些实体,ObjectSet 和 IQueryable 不能相互分配?

I'm having some troubles using the Generic repository of http://www.codeproject.com/KB/architecture/RepositoryUnit.aspx

There is a line of code in "FetchEntityName" that seems to crash for some entities and not for some other entities, they are all made the same way tough!.

I narrowed it down to this watch expression returning false. (i took 18 as an indexer because that's one of the entities (Group) that doesn't seem to work well)

typeof(IQueryable<>).MakeGenericType(typeof(T)).IsAssignableFrom(this.ObjectContext.GetType().GetProperties()[18].PropertyType)

returns false!
left side:

typeof(IQueryable<>).MakeGenericType(typeof(T))   

returns in watch:

{Name = "IQueryable`1" FullName = "System.Linq.IQueryable`1[[Domain.Groep, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}    System.Type {System.RuntimeType}

right side:

this.ObjectContext.GetType().GetProperties()[18].PropertyType

returns in watch:

{Name = "ObjectSet`1" FullName = "System.Data.Objects.ObjectSet`1[[Contacts.Groep, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}    System.Type {System.RuntimeType}

In english?

Why aren't ObjectSet and IQueryable assignable to one another for some entities in my EDMX?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-12-31 18:31:59

我有第二个 EDMX,其中包含一个 groep 实体,它导致了所有这些麻烦。

简单地删除重复的实体即可修复它-;)

I had a second EDMX that contained a groep entity, wich was causing all this trouble.

Simple removing the duplicate entitiy fixed it-;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文