Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

vb.net - Initialising multiple classes from one database call

I'm trying to implement some best practices into my programming, and better implement "tiers" into my applications. I'm also trying to make vast improvements to database access and application efficiency.

This happens to be a VB.Net application, but really is a general programming dilemma as far as I'm concerned.

To keep things simple, let's say I have a Client class. This has ID, Name and Account Manager properties. The Account Manager is a Staff class, with it's own ID and Name properties.

Instead of binding a DataTable to a grid, I'm binding a ClientCollection, so I can more easily access the business logic when the grid is being interacted with and changed.

Now let's say I want to present all 10,000 Clients in the grid. In my mind, this should be a single database call to obtain Client ID, Client Name, Account Manager ID, Account Manager Name - instead of initialising each Account Manager separately, 10,000 times.

I guess my questions is: What are the best practices for accessing data in this way? For each Client should I manually Initialise a Staff class by initialising a blank one and manually populating the fields I have access to? Should I even bother going to this depth, and just stick to populating the grid with a DataTable?

I can't for the life of me find any real-world examples or articles that actually assist in trying to develop software that talks to databases and separates logic layers, in a proper Object Oriented structure. Any advice whatsoever would be greatly appreciated!

Thank you.

question from:https://stackoverflow.com/questions/65617262/initialising-multiple-classes-from-one-database-call

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...