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.
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...
<asp:Parameter Name="userName" DefaultValue='<%# User.Identity.Name %>' />
...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.