EntityDataSource 是否支持“it.Property.Property”?句法?
我有一个 EntityDataSource,我试图在其中替换一些以前的代码隐藏工作。我的 EntityDataSource 看起来像:
<asp:EntityDataSource
runat="server"
ID="personDataSource"
ContextTypeName="Model.GuidesEntities"
EntitySetName="CharacterFavorites"
OrderBy="it.Person.FullName"
Select="it.Person.Id"
Where="it.UserName = @userName" />
当我实际使用它时,我收到错误:
“Person”不是类型的成员 'Transient.rowtype[(Id,Edm.Int32(Nullable=True,DefaultValue=))]' 中 当前加载的架构。
EntityDataSource 不支持遍历关系吗?您将如何使用 EntityDataSource 执行此操作?
另外,@userName
参数目前已添加到后面的代码中。对于知道如何直接在WhereParameters 集合中指定用户名参数的任何人来说,可以加分。
I have an EntityDataSource where I'm trying to replace some previous code-behind work. My EntityDataSource looks like:
<asp:EntityDataSource
runat="server"
ID="personDataSource"
ContextTypeName="Model.GuidesEntities"
EntitySetName="CharacterFavorites"
OrderBy="it.Person.FullName"
Select="it.Person.Id"
Where="it.UserName = @userName" />
When when I actually use it I get the error:
'Person' is not a member of type
'Transient.rowtype[(Id,Edm.Int32(Nullable=True,DefaultValue=))]' in
the currently loaded schemas.
Does the EntityDataSource not support walking the relationships? How would you do this with the EntityDataSource?
Also the @userName
parameter is being added in the code behind for now. Extra points for anyone who knows how to specify a username parameter directly in the WhereParameters collection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EF 在这里使用“超级延迟加载”(我自己的术语)。它不会自动伸出手来抓取关联的“Person”对象。您必须在 entotyDataSource 内指定哪些其他对象可用。所以需要添加这一行:“Include=”Person”。见下图:
如果需要添加多个关联,用逗号分隔: Include=”Person, Dog, Chicken, SalesOrder”
另外,Where 子句中是“==”而不是“=”。
EF uses "super lazy loading" here (my own term). It doesn't automatically reach out and grab the associated "Person" object. You MUST specify inside the entotyDataSource what other objects to make available. So you need to add this line: "Include="Person". See below:
If you need to add multiple associations, separate them with commas: Include="Person, Dog, Chicken, SalesOrder"
Also, it's "==" not "=" in your Where clause.
没有标准的预定义参数类型允许您将当前用户名作为标记中的Where参数获取(我猜您正在谈论
User.Identity.Name
)。 不幸的是,像...这样简单的东西不起作用,因为您无法在参数控件中使用数据绑定语法。
但是您可以创建 自定义参数。 (该页面的后半部分是“用户名参数”的具体示例。)
对于您的问题,例外:我在 EntityDataSource 中经常使用带有导航属性的“it-Syntax”,它看起来更多或不太像你的例子。如果没有看到更多的模型,就很难判断是什么导致了错误。但一般来说,支持并有效地浏览 EntityDataSource 中的属性。
There is no standard predefined parameter type which allows you to get the current user name as a Where parameter in markup (I guess you are talking about
User.Identity.Name
). Something simple like......doesn't work unfortunately since you cannot use data binding syntax in the parameter controls.
But you can create custom parameters. (On the second half of that page is a concrete example of a "user name parameter".)
To your problem with the exception: I'm using the "it-Syntax" with navigation properties a lot in EntityDataSource and it looks more or less exactly like your example. Without seeing more of your model it's hard to tell what might cause the error. But generally, navigating through properties in EntityDataSource is supported and works.