What is the correct way to use .NET DataSet?

I am trying to figure out the correct way to use .NET DataSets. Do you intend to create a DataTable for each table in your database and create relationships in a DataSet? It seems crazy to restore the entire database structure in a DataSet.

I am using a simplified example of my database. Let's say I have a table CompanyEquipment. Each piece of equipment refers to a cost center, and cost center data is stored in a table CostCenterand refers to a table CompanyEquipment. Suppose I have a stored procedure that returns CompanyEquipmentdata already connected to a table CostCenterin order to return all the information in a single query. I could use a stored procedure to populate it DataTable, but how would I save this normalized result table to a database? I do not know if this is good to do. In any case, querying a many-to-many relationship that uses association (bridge) tables will require several queries. For example, I have a table EquipmentRolethat stores various ways of using equipment, and a tableEquipmentRoleAssignmentwhere several parts can be assigned to parts of the equipment.

Alternatively, if I have DataTables that mimic the database, I would have to query each table separately using the DataAdapter.Fill () for each table to put the corresponding data in each DataTable. So I would have something like select * from CompanyEquipment where equipID = 1234that, and I would use this with the adapter to populate CompanyEquipment DataTable, and then I would have to use another request select * from CostCenter where costCenterID = <costcenterID from the companyequipment record>and populate CostCenter DataTable. With this approach, I have to hit the database twice, and I lose the ability of the DBMS to perform joins.

, , ; , , . . #.

+5
3

Datasets ( ), 0,02 $

1, 2 , .

: , .

, , , + , , , 1, , .

, , , 2, .

Insert/Update

2 , , . , datarow (//), // . 1, , .

, . , ,

: /, - - , , , . , , - , ,

+3

? DataSets .NET 1.0. ORM, . DataSets , , .

+5

I suggest using POCO with the Entity Framework. With EF, you can use the Entity Framework Power Tools , which generates POCO classes, DbContext and Code First derivatives for an existing database. This will reduce your effort in creating classes. You have classes that you can use with EF to solve the problems that you described in your question.

0
source

All Articles