实体框架返回不同的数据,然后DB查询 [英] Entity Framework returning different data then DB query

查看:90
本文介绍了实体框架返回不同的数据,然后DB查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了我的数据库中的一些数据,它返回数据,例如

 呼叫日期从电话号码
20/1/2010 00:00 23:59 08923233223
20/1/2010 00:00 23:59 08923233245

但是,当我将其添加到我的实体模型并查询时,我收到重复(和意外的)数据

 来电电话号码
20/1/2010 00:00 23:59 08923233223
20/1/2010 00:00 23:59 08923233223

我只是将Entity数据源绑定到这个实体,但是我不知道为什么数据被不同地返回



编辑:有趣的是,这不能是引擎盖下的一些奇怪的结果,因为行计数符合预期。我也自己组合一个查询,用相同的奇怪的结果来测试

 从o在App.Entities.v_PersonalRules中o。 companyid = CompanyID选择o 

我正在使用Visual Studio 2010,.NET 4



有没有人遇到过类似的问题?



编辑:前端代码相当简单


$ b $ $ = $$$$$$$$$$$ =False
EnableUpdate =TrueEntitySetName =v_PersonalRulesEntityTypeFilter =v_PersonalRules>
< / asp:EntityDataSource>

这是gridview下面的数据源



$ _ code>< asp:GridView ID =GridView3runat =serverAutoGenerateColumns =FalseDataSourceID =EDS_Personal
EnableModelValidation =TrueAllowPaging =True AllowSorting =TrueCssClass =nice_tablePagerStyle-CssClass =cssPagerAutoGenerateDeleteButton =trueAutoGenerateEditButton =true>
<列>
< asp:CommandField ButtonType =LinkEditText =EditShowEditButton =true/>
< asp:BoundField DataField =billdateHeaderText =Bill DateSortExpression =billdateDataFormatString ={0:dd-MM-yyyy}/>
< asp:BoundField DataField =starttimeHeaderText =FromSortExpression =starttimeDataFormatString ={0:t}/>
< asp:BoundField DataField =endtimeHeaderText =ToSortExpression =endtimeDataFormatString ={0:t}/>
< asp:BoundField DataField =descriptionHeaderText =TypeSortExpression =description/>
< asp:BoundField DataField =HSNumberHeaderText =Call FromSortExpression =HSNumber/>
< asp:BoundField DataField =uidHeaderText =uidSortExpression =uidvisible =true/>
< asp:BoundField DataField =dialledNoHeaderText =Calls ToSortExpression =dialledNo/>
< asp:BoundField DataField =companyidHeaderText =Company IDSortExpression =companyid/>

< / Columns>
< / asp:GridView>


解决方案

我现在解决了这个问题....问题出现由于布置的问题
这里。添加正确的实体密钥解决了问题


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>

解决方案

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

这篇关于实体框架返回不同的数据,然后DB查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆