TypedList Custom DataColumn

Posts   
 
    
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 10-Dec-2007 19:37:04   

LLBL Pro version = 2.5 final runtime version = v2.0.50727 Using ASP.NET 2.0 Database = MS SQL 2005 selfsevicing

Hi,

I have created a TypedList and added a custom DataColumn to it. In my partial TypedList class, I would like to be able to set the DefaultValue of my custom column after the TypedList/DataTable is populated with data. The reason for this is that my custom column value must be retrieved from the database based on a value of another column in the TypedList. I have spent several hours working on this but can not find a method to override or method to add custom code to in order to acomplish the above. Can someone please point me in the right direction?

TIA, Rich

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 10-Dec-2007 20:12:22   
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 10-Dec-2007 23:42:41   

goose wrote:

see this for more information:

http://llblgen.com/TinyForum/Messages.aspx?ThreadID=6254

Hi goose,

I came across that post in my research. I've already created the DataColumn in my TypedList. What I need to know is whether there is any way to initialize the column with a value after the TypeList gets populated from the database. I need to initialize the DataColumn value by retrieving a value from another table based on a value of one of the DataColumns in my TypedList. I don't think using the Expression property of the DataColumn (as suggested in the post in pointed me to) will work in my case.

Rich

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Dec-2007 05:28:52   

Hi Rich. What if you just return the value from the yourTypedListRow.yourNewColumn property?

namespace Northwind.TypedListClasses
{
    public partial class MyProductListTypedList
    {       
        private DataColumn _extraColumn;

        protected override void OnInitialized()
        {
            _extraColumn = new DataColumn("ExtraColumn", typeof(int), null, MappingType.Attribute);
            _extraColumn.ReadOnly = true;
            this.Columns.Add(_extraColumn);
            base.OnInitialized();           
        }

        internal DataColumn ExtraColumn
        {
            get { return _extraColumn; }
        }
    }


    public partial class MyProductListRow
    {
        public int ExtraColumn
        {
            get
            {
                int valueToReturn = 0;

                // play with your datacolumns
                valueToReturn = this.ProductId + 10000;

                return valueToReturn;
            }           
        }
   }

David Elizondo | LLBLGen Support Team
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 11-Dec-2007 19:46:01   

Hi David,

I did exactly that (using llbgen regions, not partial classes) and did not work. I should probably mention that I'm using llbgendatasource control to bind to a gridview in my asp.net page.
I even placed a break point at the property accessor in the TypedListRow class, but the breakpoint was never hit, not even for the other mapped properties in the TypeListRow class...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Dec-2007 11:11:34   

We can't help without seeing your code, would you please attach a repro solution? Thanks.

rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 12-Dec-2007 17:21:48   

Walaa wrote:

We can't help without seeing your code, would you please attach a repro solution? Thanks.

Hi Walaa,

I would like to attach a sample project, but your upload limit is 256KB which too small...When zipped the project is 1MB. Can I email you the project?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Dec-2007 17:34:14   

Try to zipp it without the bin or obj folders, just the code files.

Also you can e-mail it to support AT llblgen DOt com And refer to this thread in your e-mail.

rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 12-Dec-2007 17:51:48   

Walaa wrote:

Try to zipp it without the bin or obj folders, just the code files.

Also you can e-mail it to support AT llblgen DOt com And refer to this thread in your e-mail.

Here it is w/o the llblgen dlls. I added a DataColumn 'MyColumn' to the CustomerTypedList class, and MyColumn property to the CustomerRow class. The MyColumn accessor in the CustomerRow class should return string concatenated from two other properties in that class. When you run the project you will see that the DataGrid's 'MyColumn' holds no values.

Thanks for looking at this.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Dec-2007 12:25:36   

I think in order to populate your custom column, you have to either do this on the database side or in the code as you want.

Doing it from code I think you should manually loop on the TypedList from an outside code (the caller code) after being fetched, and manually populate the the custom column/field.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 13-Dec-2007 12:55:31   

Why not add an expression column to the datatable which returns the value of two columns concatenated? (expression column is a datacolumn with an expression set as its value) If you don't do it that way, you have , as Walaa said, populate the column manually.

Frans Bouma | Lead developer LLBLGen Pro
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 13-Dec-2007 15:27:00   

Otis wrote:

Why not add an expression column to the datatable which returns the value of two columns concatenated? (expression column is a datacolumn with an expression set as its value) If you don't do it that way, you have , as Walaa said, populate the column manually.

Yes that would work for concatenating column values, but what I have to do is grab a value of one of the columns and use it in fetching a value from the db, and then used the fetched value to populate my custom column value. I know I can do all this if I populate the TypeList manually and then set a value on my custom column. I was hoping the custom column could be populated by the TypedList class after it populates the values of the other columns. The calling code wouldn't have to deal with populating the custom column and/or the developer could use the llblgendatasource for databinding unaware of how the custom column was populated. Can this be done???

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Dec-2007 15:38:57   

Would you please describe/sketch your schema, and post the corresponding SQL queries that you want to excute to fetch the TypedList and to fetch the extra column values?

rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 14-Dec-2007 15:53:43   

Walaa wrote:

Would you please describe/sketch your schema, and post the corresponding SQL queries that you want to excute to fetch the TypedList and to fetch the extra column values?

Lets assume I have two tables, one tabel is mapped onto a TypedList one is an external tabel that can not be mapped using llbllgen. I add a custom column to the TypedList. I want the TypedList to use the value of one of the mapped columns as a parameter in fetching a scalar value from the unmapped table and populate my custom column with the fetched value. I want all of this to happen when the llblgenpro datasource binds to the TypedList (no external code, the TypedList should handle the populating of the custom column). Is the above possible?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Dec-2007 16:20:52   

I don't think it's possible in the way you have described it.

If you don't want to map the external table in LLBLGen, then I suggest you do the follwowing: Create a User/Custom Database Function to be calles in the SelectList to return the required data, which you can use from LLBLGen code using a DBFunctionCall, which will return an Expression to be used in the extra column of the TypedList.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Dec-2007 06:26:50   

rihadd wrote:

Lets assume I have two tables, one tabel is mapped onto a TypedList one is an external tabel that can not be mapped using llbllgen. I add a custom column to the TypedList. I want the TypedList to use the value of one of the mapped columns as a parameter in fetching a scalar value from the unmapped table and populate my custom column with the fetched value. I want all of this to happen when the llblgenpro datasource binds to the TypedList (no external code, the TypedList should handle the populating of the custom column). Is the above possible?

You could also opt for inherit from the original typedList, then you could add your custom column, then you should grab the custom/in-memory-calculated-values internally, overriding the Fill method and put your code there. You always have to iterate and grab but in this way you can do that inside the typedList.

David Elizondo | LLBLGen Support Team