查询多个复杂对象 [英] Querying Multiple Complex Objects

查看:131
本文介绍了查询多个复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有人,



我正在尝试获取一些信息/最佳实践,用于从数据库查询多个复杂对象到我的c#对象。我觉得我当前的进程表现不尽如人意。



我有一个自定义编写的DataAccess类,它打开一个连接,获取一个DataSet然后关闭连接。因此,当我查询100个这样的复杂对象时,我基本上迭代了我需要获取的ID并为每个ID进行数据库调用。让我走的任何想法/方法?谢谢!



ATCSharp

Hey Everyone,

I am trying to get some information/best practices for querying multiple complex objects from a database to my c# objects. I feel that my current process is not performing as well as it could be.

I have a custom written DataAccess class that opens a connection, gets a DataSet and then closes the connection. So when I query 100 complex objects like this I am essentially iterating over the IDs that I need to get and making a database call for each. Any ideas/methodologies to get me going? Thanks!

ATCSharp

推荐答案

我通常做的是将数据集的每个对象设置为一个类并制作一本词典。



例如。您从人员表中选择一群人。您创建一个Person类,每一行都是添加到Dictionary的新实例,该表将主键值作为Dictionary键,Person类实例作为值。



但我同意你的问题有点模糊的评论。但是我提到的解决方案很常见。



如果您正在使用SQL Server,请考虑LINQ to SQL。
What I usually do is set each object of the dataset into a class and make a Dictionary.

eg. You select a bunch of persons from the person table. You create a Person class and each row is a new instance added to a Dictionary that has the tables primary key value as Dictionary key and the Person class instance as value.

But I agree with the comments that your question is a bit vague. However the solution I mentioned is pretty common.

If you're working with SQL Server, consider LINQ to SQL.


这篇关于查询多个复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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