Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:54:25+00:00 2026-05-26T22:54:25+00:00

I’m using LINQ to Entities My GridView is the following : <asp:GridView ID=GridView1 runat=server

  • 0

I’m using LINQ to Entities

My GridView is the following :

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
    EmptyDataText="No Data" CellPadding="3" CellSpacing="1"
    AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit"
    OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" CssClass="gridview"
    OnSorting="GridView1_Sorting" HorizontalAlign="Center">
    <AlternatingRowStyle BackColor="#F0F0F0" />
    <Columns>
        <asp:BoundField HeaderText="ID" DataField="ID" ReadOnly="True" SortExpression="ID" />
        <asp:BoundField HeaderText="Name" DataField="SoftwareName" SortExpression="Name" />
        <asp:BoundField HeaderText="Key" DataField="Key" SortExpression="Key" />
        <asp:BoundField HeaderText="Date" DataField="Date" ItemStyle-CssClass="date_td" SortExpression="Date"
            ReadOnly="True">
            <ItemStyle CssClass="date_td"></ItemStyle>
        </asp:BoundField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton runat="server" ToolTip="edit" ID="EditButton" CommandName="Edit"
                    ImageUrl="~/images/edit.png" />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:ImageButton runat="server" ID="UpdateButton" ToolTip="Submit" CommandName="Update"
                    ImageUrl="~/images/ok.gif" />
                <asp:ImageButton runat="server" ID="Cancel" ToolTip="Submit" CommandName="Cancel"
                    ImageUrl="~/images/cancel.gif" />
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton runat="server" ToolTip="Delete" ID="btnDelete" CommandName="cDelete"
                    ImageUrl="~/images/delete.png" OnCommand="OnDelete" CommandArgument='<%# Bind("id") %>'
                    OnClientClick="return confirm('Are you sure ?')" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <PagerSettings Mode="NumericFirstLast" />
</asp:GridView>

I fill the GridView with the following c# code :

private IQueryable SortGridView()
{
    IQueryable<Softwares> softwares = Search();

    if (softwares == null) return null;

    string sortExpression = (ViewState["SortExpression"] as string) == null
                                ? "ID"
                                : ViewState["SortExpression"] as string;
    string lastDirection = (ViewState["SortDirection"] as string) == null
                                ? "ASC"
                                : ViewState["SortDirection"] as string;

    switch (sortExpression)
    {
        case "ID":
            softwares = (lastDirection == "ASC")
                                ? softwares.OrderBy(q => q.id)
                                : softwares.OrderByDescending(q => q.id);
            break;

        case "Name":
            softwares = lastDirection == "ASC"
                            ? softwares.OrderBy(q => q.softwareName)
                            : softwares.OrderByDescending(q => q.softwareName);
            break;

        case "Key":
            softwares = (lastDirection == "ASC")
                            ? softwares.OrderBy(q => q.Keys.Key)
                            : softwares.OrderByDescending(q => q.Keys.Key);
            break;

        case "Date":
            softwares = lastDirection == "ASC"
                            ? softwares.OrderBy(q => q.Date)
                            : softwares.OrderByDescending(q => q.Date);
            break;
    }

    return from q in softwares
            select new
                        {
                            ID = q.id,
                            SoftwareName = q.softwareName,
                            Key = q.Keys.Key
                            Date = q.Date.ToString()
                        };
}

protected void ButtonSearch_Click(object sender, EventArgs e)
{
    GridView1.DataSource = SortGridView();
    GridView1.DataBind();// <<--- Exception
}

But in ButtonSearch_Click I get the following exception :

LINQ to Entities does not recognize the method ‘System.String ToString()’ method, and this method cannot be translated into a store expression

I’ve done it before with the LINQ to SQL without any problems, what is wrong with it here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:54:26+00:00Added an answer on May 26, 2026 at 10:54 pm

    LINQ to Entities queries are internally converted into sql statements. In your case its just that, LINQ to Entity provider is not able to map the “toString” call into a suitable SQL statement. You can retrieve the data from LINQ to entity and then enumerate offline and make the necessary changes i.e. :

    var data = (from q in softwares
                select new
                            {
                                ID = q.id,
                                SoftwareName = q.softwareName,
                                Key = q.Keys.Key
                                Date = q.Date
                            }).ToList();
    

    and then convert the Date part by calling ToString() method offline.

    data.ForEach(item => item.Date = item.Date.ToString());
    

    You are returning anonymous type from your method. Anonymous types are accessible only within the class where they are defined. You can try something like the code I have given below :

    private IList<SoftwareInfo> SortGridView()
    {
        // regular code
    
        return (from q in softwares
                select new SoftwareInfo
                            {
                                ID = q.id,
                                SoftwareName = q.softwareName,
                                Key = q.Keys.Key,
                                Date = q.Date
                            }).ToList();
    }
    
    
    public class SoftwareInfo
    {
        public int ID {get;set;}
        public string SoftwareName {get;set;}
        public string  Key {get;set;}
        public DateTime Date {get;set;}
    }
    
    protected void ButtonSearch_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = SortGridView();
        GridView1.DataBind();// <<--- Exception
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.