如何使用实体框架获取sql数据(包括链接数据1- *) [英] How do I fetch sql data (including linked data 1-*) using entity framework

查看:83
本文介绍了如何使用实体框架获取sql数据(包括链接数据1- *)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我通过LINQ to SQL dbml对象连接到我的数据库。当我搜索客户时,我也需要获得几个链接表。

这些包括付款细节,联系历史,索赔历史等...



我使用分页,所以我的数据集不会很大。我想在一次点击中获得所有数据,但如果我不能这样做,那么我只需要单独获得结果。这不是一个大问题,但它确实使我的保存和编辑功能更复杂。



我需要结果是IQueryable,因为这是我的分页,过滤和排序工作。如果我使用存储过程。那么我就不得不对那些用作参数的工程进行逆向工程,这样就会产生很多混乱:S $ / b


我现在还有意义吗?也许星期五咖啡太多了:S



谢谢^ _ ^

Andy






PS:一些强制性代码

  //  详细信息是包含所有可编辑数据的对象。它被传递给每个控件,以便他们可以填写控件。 
var data = details.PaymentDetails;
// 链接表对象具有用于分页的数据和总计。页面大小和索引由网格决定

var pageSize = 5
sort = user.settings.PaymentDetails.Sort, // default []
group = user.settings.PaymentDetails.Group, // default []
filter = user.settings.PaymentDetails.Filter, // default []
列= user.settings.PaymentDetails.Columns // 默认PaymentType,状态
// 这适用于熟悉Kendo控件的人
var dataSource = new kendo.data.DataSource({
data:data,
schema:{
总计: 总计
数据: 数据
型号:{
id: Id
},
serverPaging: true
serverFiltering: true
serverSorting: true
pageSize:pageSize,
sort:sort,
filter:filter,
group:group
});





一些博览会,好像你真的在乎:P

这个想法是包含这些选项卡子控件( CustomerDetails 。, PaymentDetails 等)的主控件( CustomerManagement )将根据原始值检查更改。最后一个选项卡控件是 SaveChanges ,它总结了允许用户知道哪些更改需要管理员授权等的更改,以及系统中新细节之后可用的操作。

哦,这部分是供我们的代理商(电话运营商)使用的。它必须是快速的(信号器),动态的(与当前登录的所有其他代理程序相互链接,再次:信号器),并且是防欺诈的;因此,为什么我不会让用户在未经授权的情况下更改付款细节。

解决方案

这回答了这个问题:



引用:Richard Deeming于8月21日 - 8月15日上午11:20





您是否正在寻找 包含方法 [ ^ ]?

实体框架:加载相关实体 [ ^ ]

加载相关实体实体框架 - 初学者入门 [ ^ ]


Hi,

I am connected to my db via LINQ to SQL dbml objects. When I search for customers I need to get several linked tables too.
These include things like Payment Details, contact history, claim history etc...

I use paging so my data sets won't ever be very big. I would like to get all the data in one hit, but If I can't do it then I'll just have to get the results individually. This isn't a huge issue but it does make my save and edit features much more complex.

I need the result to be IQueryable as this is how my paging, filtering and sorting works. If I use a Stored Proc. then I would have to reverse engineer those to be used as parameters, and that way much messiness lies :S

Am I even making sense at this point? Maybe too much coffee for a friday :S

Thanks ^_^
Andy



PS: Some obligatory code

// details is my object that contains all of the editable data.  It is passed to each control so they can fill in their controls.
var data = details.PaymentDetails;
//The linked table objects have Data and Total used for paging.  Page size and index is dictated by the grid

var pageSize = 5,
    sort = user.settings.PaymentDetails.Sort, // default []
    group = user.settings.PaymentDetails.Group,// default []
    filter = user.settings.PaymentDetails.Filter,// default []
    columns = user.settings.PaymentDetails.Columns// default PaymentType, Status
//This is for those familiar with Kendo controls
var dataSource = new kendo.data.DataSource({
    data: data,
    schema: {
                total: "Total",
                data: "Data",
                model: {
                    id: "Id"
             },
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true,
    pageSize: pageSize,
    sort: sort,
    filter: filter,
    group: group
});



Some exposition, as if you really care :P
The idea is that the main control (CustomerManagement) that contains these tabs child controls (CustomerDetails., PaymentDetails. etc) will check the changes against the original values. The last tab control is SaveChanges which summarizes the changes letting the user know which changes require Admin authorization etc, and what actions are available after the new details are in the system.
Oh, this section is for our Agents (telephone operators) to use. It has to be fast (signalr), dynamic (interlinked with every other agent currently logged in, again: signalr), and be fraud resistant; hence why i won't let users change payment details without authorization.

解决方案

This answered this question:

Quote: Richard Deeming at 21-Aug-15 11:20am



Are you looking for the Include method[^]?
Entity Framework : Loading Related Entities[^]
Loading Related Entities with Entity Framework - A Beginner's Primer[^]


这篇关于如何使用实体框架获取sql数据(包括链接数据1- *)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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