Inherits Project.vb Problem??

Inherits Project.vb Problem??

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


khoogavin posted on Monday, April 27, 2009

I have 1 BO let said Project_BO.vb. It inherits Project.vb.

In GetProject function, I use Project_BO.GetQuotation(id) instead of Project.GetQuotation(id) .

And it return an error message

Exception Details: System.InvalidCastException: Unable to cast object of type 'ProjectTracker.Library.Project' to type 'ProjectTracker.Library.Project_BO' .

Line 184:        Return CType(businessObject, Project_BO)

Thanks for helping.

RockfordLhotka replied on Monday, April 27, 2009

It is difficult to do inheritance from a non-generic type, when the higher base classes are generic.

BusinessBase<T> is generic, and T is the type that inherits from BusinessBase<T>, and so there's code at that level that expects T to be your business type (Project). By subclassing Project, you are confusing the base class (and maybe the data portal).

You really have two options.

  1. You can inherit from Csla.Core.BusinessBase, which is not generic. Then you can use non-generic inheritance all the way through your object model. You'll have to do a little extra work to replace the behaviors in BusinessBase<T> with non-generic equivalents (accepting/returning values of type object instead of T).
  2. You can make your base class be generic. Project<T> instead of Project. I'd recommend doing this, as it makes better use of existing CSLA functionality, and this has been discussed many times on the forum, so there are many good examples.

 

Copyright (c) Marimer LLC