none
Compatibility Issue Entity Data Source with EF 6.0 RRS feed

  • Question

  • Hello,

    In a new Web Forms application with Entity Framework 6.0, I encounter the following problem when I try to configure the datasource of a GridView:


    I have updated all Nuget packages and as stated in the message I installed Microsoft.AspNet.EntityDataSource. All these installations went well but I still have the same problem.

    What to do ? Is there a workaround for this problem?

    Thanks in advance.

    Friday, November 25, 2016 7:43 AM

All replies

  • Hi dg78,

    The user interface isn't supported when using EF6. We no longer recommend using the Entity Data Source for new projects, so we just did the work to provide a data source that is usable with EF6. You need to perform configuration directly in the markup.

    For more information, please refer to: http://stackoverflow.com/questions/25836705/entitydatasource-and-entity-framework-6

    http://stackoverflow.com/questions/5869033/how-to-bind-gridview-using-linq-entity-framework

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 25, 2016 10:04 AM
    Moderator
  • Thanks Cole for your answer.

    I see that you copied the sentence of Rowan Miller that he made on September 15, 2014.

    That is to say that for more than two years there is always a problem and no solution.

    For me it is a bug because we can configure the datasource of a gridview with an EntityDataSource and the message in the windows error says to download a Nuget package.

    So I put a bug to the Entity Framework team :

    https://entityframework.codeplex.com/workitem/2962

    There are always new products and related products do not follow. In 2014, the new releases were VS 2015.

    Teams change, may be Ronan Miller no longer takes care of Entity Framework and the problem today is not the concern of the new team.

    On the other hand the developers remain and they are the ones who have to manage the problems.

    I'm tired of seeing this.

    Come back to the problem today :
    could you indicate an example to workaround for this problem ?  I have many tables in my database and I don’t want to write all columns by hand for the gridviews

    Thanks

    Friday, November 25, 2016 1:32 PM
  • Hi,

    Based on your description, I create a simple as below for your reference.

    #ASPX

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormApp.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server"></asp:GridView>
        </div>
        </form>
    </body>
    </html>
    

    #CodeBind

    using System;
    using System.Linq;
    using System.Web.UI.WebControls;
    
    namespace WebFormApp
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    using (var db = new EFContext())
                    {
                        var result = from p in db.Departments
                                     join u in db.Users on p.DepartmentId equals u.DepartmentId
                                     select new
                                     {
                                         UserId = u.UserID,
                                         DepartmentName = p.DepartmentName,
                                         UserName = u.UserName
                                     };
                        GridView1.DataSource = result.ToList();
    
                        GridView1.DataBind();
                    }
                }
    
            }
        }
    }

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 28, 2016 6:47 AM
    Moderator
  • This was what Worked for me

    Go to Tools->nugget package manager->Package manager console

    in the package manager console displayed at the bottom of the editor, type 

     Install-Package Microsoft.AspNet.EntityDataSource 

    After the installation, check to see if the tag below is in your web.config file 

    <pages> .

    .

    . <controls> .

    .

    . <add tagPrefix="ef" assembly="Microsoft.AspNet.EntityDataSource" namespace="Microsoft.AspNet.EntityDataSource" />

    </controls> </pages>

    in your .aspx page change  this tag  <asp:EntityDataSource..../asp:EntityDataSource> 

     To

    <ef:EntityDataSource ID="EntityDataSource1" runat="server" ContextTypeName=""
                          EntitySetName="" EnableFlattening="false" EnableDelete="true" EnableUpdate="true" EnableInsert="true"> 
                    </ef:EntityDataSource>


    Thursday, February 7, 2019 3:45 PM