passing objects into methods that do database processing?

  • Thread starter Thread starter Andy B
  • Start date Start date
A

Andy B

Is it good (or should I say normal) practice to pass an object into a method
for database processing? Or should I stay away from that sort of thing.
 
Andy,

I don't think it is bad practice, but I wouldn't say that you start to
look into passing everything as an object. What exactly are you trying to
pass into the database, and why?
 
I am working on a news section of a website. This section will be able to
add, edit and delete news articles from the database. Right now I have a
NewsHelper class that does all of the database work for the news sections of
the website. At this point the NewsHelper class has The methods GetNews,
NewsCount, GetNewsByNewsID, GetNewsByCategoryId, GetCategoryCount,
GetCategoriesByNewsID and so on. Anyways, What I need to do is take
something that represents a newsItem and insert the whole thing into the
database along with cross referencing the news article with the categories
it goes under in the NewsHeaders table. I have a dll called News that has
the helper class and probably the NewsItem object or data type depending how
things should go. This is what the NewsItem object looks like:
NewsID - identity(1,1) int (the NewsID number).
Date - DateTime (The date/time the news article was posted).
Title - varchar(50) [will probably change to varchar(MAX)] (The news article
title/subject line).
Text - Text (the body of the news article).
Categories - a <List>Categories colllection of the categories the news
article is filed under. The categories list is under a different database
table than the other properties of the news article.

What I need to do is go through this object and make sure that everything is
done right and then put it in the database. Any ideas on how this should be
done? I am hoping to be able to reuse the NewsItem object (or whatever it is
I should use) and the NewsHelper class in a different project. I eventually
plan on making a winforms program that will be able to update the website
and stuff as well. So, most of this code should be reusable. Any advise is
helpful on how I should do this...


Nicholas Paldino said:
Andy,

I don't think it is bad practice, but I wouldn't say that you start to
look into passing everything as an object. What exactly are you trying to
pass into the database, and why?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Andy B said:
Is it good (or should I say normal) practice to pass an object into a
method for database processing? Or should I stay away from that sort of
thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top