I have a GridView associated with an EntityDataSource.
EntityDataSource has an internal parameter for Where parameters. Everything is working fine up to this point.
<asp:EntityDataSource ID="EntityDataSourceListAuthors" runat="server" ConnectionString="name=CmsConnectionStringEntityDataModel"
DefaultContainerName="CmsConnectionStringEntityDataModel" EnableFlattening="False"
EntitySetName="CmsAuthors" EntityTypeFilter="" OrderBy="it.FirstName" Select="it.AuthorId, it.UserId, it.FirstName, it.LastName, it.NoteInternal, it.ContentAuthor"
Where="it.UserId = @ActiveUser">
</asp:EntityDataSource>
I am using Event RowDataBound for the Entity Framework to retrieve the value for each individual row and execute some logic.
As soon as I run the code, I get this error:
Unable to cast object of type 'System.Data.Objects.MaterializedDataRecord' to type 'WebProject.DataAccess.DatabaseModels.CmsAuthor'.
It seems to me that when adding parameters to EntityDataSource smt changes, so I can not use EF, as before Any ideas? Thanks guys!
protected void uxListAuthorsDisplayer_RowDataBound(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
WebProject.DataAccess.DatabaseModels.CmsAuthor myRow = (WebProject.DataAccess.DatabaseModels.CmsAuthor)e.Row.DataItem;
Guid myUserGuid = (Guid)myRow.UserId;
MembershipUser mySelectedUser = Membership.GetUser(myUserGuid);
e.Row.Cells[3].Text = mySelectedUser.UserName;
using (CmsConnectionStringEntityDataModel context = new CmsConnectionStringEntityDataModel())
{
int myWorkingRowId = myRow.AuthorId;
HyperLink myEditLink = (HyperLink)e.Row.FindControl("uxLinkEditButton");
LinkButton myDeleteButton = (LinkButton)e.Row.FindControl("uxLinkDeleteButton");
Label mySystemNote = (Label)e.Row.FindControl("uxSystemNoteDisplayer");
CmsContent authorIdInContent = context.CmsContents.FirstOrDefault(x => x.AuthorId == myWorkingRowId);
if (authorIdInContent != null)
{
myDeleteButton.Visible = false;
mySystemNote.Text = "Author is being used in Contents";
}
else
{
myDeleteButton.Visible = true;
}
myEditLink.Visible = User.IsInRole("CMS-ADMINISTRATOR") || User.IsInRole("CMS-AUTHOR") || User.IsInRole("CMS-EDITOR");
myDeleteButton.Visible = User.IsInRole("CMS-ADMINISTRATOR");
}
break;
}
}
source
share