Need Help with DbBlogProvider.cs

Topics: Business Logic Layer
Apr 23, 2009 at 3:09 AM
Edited Apr 23, 2009 at 3:28 AM
I need to add a switch statement that will allow me to change the query and select different columns or from a different table. Is there a way for me to select an additional column in List<Post> FillPosts() then pass that value as a parameter through Profile SelectPost(Guid id) to be used in a switch statement? I can't seem to figure it out. Is this the best way to go about it? If not can someone recommend a better approach?

Thanks
Apr 23, 2009 at 3:51 AM
What is it you're trying to accomplish? If you want to change one column to another, you'll probably have to create your own blog provider (or alter the select statement in your own copy of the BE.Net codebase). If you want to add a property to Post objects (which is really the only way to get more data out of SelectPost), you'll probably have to create your own blog provider and a class that inherits from Post for it to return. Does that make sense?
Apr 23, 2009 at 5:10 AM
From what I can see, it executes List<Post> FillPosts() in DbBlogProvider.cs and gets the Id of all the posts then loops through executing SelectPost(Guid id) passing in each Id and retrieving the Post data. I would like to select a column in addition to the Id in List<Post> FillPosts() and pass both the Id and the new parameter to SelectPost(Guid id). I would then use the new parameter in SelectPost(Guid id) to dynamically change the query.

Here's what I've come up with so far:

1) List<string> postIds = new List<string>(); to Dictionary<string, string> postIds = new Dictionary<string, string>(); in DbBlogProvider, line 489

2) string sqlQuery = "SELECT PostID FROM " + tablePrefix + "Posts "; to string sqlQuery = "SELECT PostID, Level FROM " + tablePrefix + "Posts "; in DbBlogProvider.cs, line 500

3) postIDs.Add(rdr.GetGuid(0).ToString()); to postIDs.Add(rdr.GetGuid(0).ToString(), rdr.GetString(1)); in DbBlogProvider.cs, line 510

4) foreach (string id in postIDs)                     to    foreach (KeyValuePair<string, string> kvp in postIds)
          posts.Add(Post.Load(new Guid(id)));              posts.Add(Post.Load(new Guid(kvp.Key), kvp.Value)); in DbBlogProvider.cs, line 516

5) I then updated the SelectPost methods in BlogProvider.cs, BlogService.cs and DbBlogProvider.cs to include the additional parameter.

All this so that I could finally use the new parameter in a switch statement like so public override Post SelectPost(Guid id, string level) in DbBlogProvider.cs so that I could dynamically change the select query.

I was getting a build error in BusinessBase.cs where DataSelect() was being called (being invoked without the new second parameter) but I couldn't change it here because not all of the blogs utilized this new parameter so I created another BusinessBase.cs page that would only be used by the new functionality and the problem was solved.

I would still like to know if there is a more elegant way to accomplish this. If anyone has any suggestions I'd love to hear them.