Dean
Dean

Reputation: 5946

Entity Framework returning different data then DB query

I have a view on some data in my database it returns the data as I would expect, for example

Call Date    To     From   Phone Number
20/1/2010    00:00  23:59  08923233223
20/1/2010    00:00  23:59  08923233245

However when I have added this to my Entity Model and query it I get duplicate(and unexpected) data appearing

Call Date    To     From   Phone Number
20/1/2010    00:00  23:59  08923233223
20/1/2010    00:00  23:59  08923233223

I am simply binding a Entity Data Source to this Entity but I am left scratching my head as to why the data is being returned differently

EDIT: Interestingly this can't be the result of some strange under the hood join as the row counts match as expected. I have also put together a query myself to test with the same odd results

From o In App.Entities.v_PersonalRules Where o.companyid = CompanyID Select o

I am using Visual Studio 2010, .NET 4

Has anyone experienced similar problems?

EDIT: The front end code is fairly simple

  <asp:EntityDataSource ID="EDS_Personal" runat="server" ConnectionString="name=Entities_NEW"
                                    DefaultContainerName="Entities_NEW" EnableDelete="True" EnableInsert="False"
                                    EnableUpdate="True" EntitySetName="v_PersonalRules" EntityTypeFilter="v_PersonalRules" >
                                </asp:EntityDataSource>

which is the data source for the gridview below

<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataSourceID="EDS_Personal"
                                    EnableModelValidation="True" AllowPaging="True" AllowSorting="True" CssClass="nice_table" PagerStyle-CssClass="cssPager" AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" >
                                    <Columns>
                                          <asp:CommandField ButtonType ="Link" EditText="Edit" ShowEditButton="true" />
                                          <asp:BoundField DataField="billdate" HeaderText="Bill Date" SortExpression="billdate" DataFormatString="{0:dd-MM-yyyy}"  />
                                          <asp:BoundField DataField="starttime" HeaderText="From" SortExpression="starttime" DataFormatString="{0:t}"/>
                                          <asp:BoundField DataField="endtime" HeaderText="To" SortExpression="endtime" DataFormatString="{0:t}" />
                                          <asp:BoundField DataField="description" HeaderText="Type" SortExpression="description" />
                                          <asp:BoundField DataField="HSNumber" HeaderText="Calls From" SortExpression="HSNumber" />
                                          <asp:BoundField DataField="uid" HeaderText="uid" SortExpression="uid" visible="true"/>
                                          <asp:BoundField DataField="dialledNo" HeaderText="Calls To" SortExpression="dialledNo" />
                                          <asp:BoundField DataField="companyid" HeaderText="Company ID" SortExpression="companyid" />

                                    </Columns>
                                </asp:GridView>

Upvotes: 2

Views: 2373

Answers (2)

Dean
Dean

Reputation: 5946

I have now solved the issue....the problem arose due to the issues laid out here. Adding the correct entity key solved the issue

Upvotes: 4

E.J. Brennan
E.J. Brennan

Reputation: 46839

First thing you should do is capture (using profiler) the sql that is being sent from EF to the server; then paste that into query analyzer and see what results you get back when you run it manually....that'll tell you if it is a client/front-end issue, versus a server issue. (I suspect front end).

Upvotes: 0

Related Questions