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