Program won't retrieve all child rows from sproc

Program won't retrieve all child rows from sproc

Old forum URL: forums.lhotka.net/forums/t/876.aspx


albruan posted on Friday, August 11, 2006

I have a sproc that retrieves department information based on the department chosen and then, through a separate Select statement, retrieves all drawings for that department.  It's a really simple sproc, similar to that used for authentication and authorization:

SELECT * FROM Departments
WHERE DeptName = @Name

SELECT * FROM Drawings dr, Departments de
WHERE (dr.DeptID = de.ID) AND (de.DeptName = @Name)

The sproc runs great in SQL Server Management Studio...returns the Department data and all three rows of test Drawing data having a DeptID equal to the Department ID.  If I try executing it from Server Explorer in the VS IDE, it returns nothing for either Select statement.  If I execute it from inside my application, it populates the Department object with the appropriate data, but it only populates one Drawing object in my Drawings collection; in other words, the SafeDataReader passed to the child Fetch method says there's only one row returned from the second Select statement.

What gives?

albruan replied on Friday, August 11, 2006

Much as I hated having to do it, I went back and made a few changes to the data tables and regenerated my Department, Drawings and Drawing objects...sooooo, I'm able to retrieve all the child rows.

My problem now is creating a new Drawing object; to test the Fetch methods, I fat-fingered data into the Drawings table.  The Department object gets created and populated, but I can't for the life of me figure out how to add a Drawing object.  I thought maybe something like

Dept.Drawing dwg = Library.Drawing.NewDrawing();

but that doesn't work since the NewDrawing method isn't exposed.  So, I tried Dept.Drawing.NewDrawing(); to the right of the equal sign...again, no such luck.  I didn't seem to have this much difficulty using 1.5x of CSLA, so why am I having it now?  *sigh*

Allen

Brian Criswell replied on Friday, August 11, 2006

Well, I have not seen your code, but my guess is that Drawing is part of a child list in Department.  I am also guessing that Drawing.NewDrawing() is internally scoped.  So you would need Department.Drawings.AddNew() to get a new Drawing.  You would override DrawingList.AddNewCore() to do the following:

protected override Drawing AddNewCore()
{
    Drawing obj = Drawing.NewDrawing();
    this.Add(obj);
    return obj;
}

You might also need to set this.AllowNew = true; in DrawingList's constructor.

BusinessListBase inherits from BindingList<T>.  Implementing AddNewCore() (and maybe AllowNew = true, I forget the default value) will enable the AddNew() method.

Copyright (c) Marimer LLC