You cannot bind a user identifier declaratively in markup directly to an EntityDataSource. But there are basically two workarounds:
The first one is simpler, but requires code. You can use the generic asp:Parameter and set its value in the code for the user ID:
Markup:
<asp:EntityDataSource ID="MyEntityDataSource" runat="server" ConnectionString="name=MyContext" DefaultContainerName="MyContext" EntitySetName="MyObjectSet" AutoGenerateWhereClause="False" Where="it.Username = @Username" <WhereParameters> <asp:Parameter Name="Username" Type="String" /> </WhereParameters> </asp:EntityDataSource>
Code for:
protected void Page_Load(object sender, EventArgs e) { MyEntityDataSource.WhereParameters["Username"].DefaultValue = User.Identity.Name; }
The second way is to create a custom parameter . An example of how to do this is shown here . Note. The example is based on asp:SqlDataSource , but it should work for EntityDataSource if you make sure that you use WhereParameters in EntityDataSource instead of SelectParameters in SqlDataSource.
source share