查询多个复杂对象

编程入门 行业动态 更新时间:2024-10-10 10:31:28
本文介绍了查询多个复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿所有人, 我正在尝试获取一些信息/最佳实践,用于从数据库查询多个复杂对象到我的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.

更多推荐

查询多个复杂对象

本文发布于:2023-10-23 02:50:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!