Just because I was curious I implemented a GetProducts() and
GetPrograms() in the repository and then explicitly set up a list of
AssetBase to add them to. It passed, so something regarding the way
NHibernate uses an abstract base with collections?
AssetRepository repository = new AssetRepository();
IList<AssetBase> assets = new List<AssetBase>();
var products = repository.GetProducts();
var programs = repository.GetPrograms();
foreach (Product product in products)
{
assets.Add(product);
}
foreach (Program program in programs)
{
assets.Add(program);
}
Assert.IsNotEmpty(assets.ToArray<AssetBase>());
On Mar 30, 9:58 am, rhartzog <[email protected]> wrote:
> I tried that also. I have deduced that the error is thrown on
> the .List<AssetBase>(); part of the Criteria. Appreciate the help
> while I continue to dig. I'm sure it's user error, just trying to
> understand why my approach is a bad idea or if the approach is sound
> how I can achieve the desired results.
>
> On Mar 30, 9:51 am, Kim Johansson <[email protected]>
> wrote:
>
>
>
> > Bah, I was too quick to answer, ignore my answer.
>
> > Med vänliga hälsningar,
> > Kim Johansson
> > Industritorget Sweden AB
> > Söndrumsvägen 29
> > 302 39 Halmstad
> > tel: 035 - 260 32 00
> > fax: 035 - 12 24 83
> > epost: [email protected]
> > webb:http://www.industritorget.se
>
> > -----Original Message-----
> > From: [email protected] [mailto:[email protected]] On Behalf
> > Of rhartzog
> > Sent: den 30 mars 2010 16:17
> > To: nhusers
> > Subject: [nhusers] Re: Abstract instantiation exception
>
> > My apologies, the line reading "Assert.IsNotEmpty(products); " should
> > read "Assert.IsNotEmpty(assets);". This is just a typo here but is
> > not reflected in code.
>
> > On Mar 30, 9:13 am, rhartzog <[email protected]> wrote:
> > > I am getting an error "Cannot instantiate abstract class..." with
> > > 2.1.2.4000 where I was not with 2.1.0.1001 and could use some help
> > > please. I am simply trying to test getting a list of the base class
> > > that would allow me to then later filter with GetAssets().Where(a => a
> > > is Product), etc. I did see the post regarding composite-id and this
> > > error, but what is strange is that I was able to run this exact test
> > > with 2.1.0.1001 on another project but now it fails. Here is the
> > > information:
>
> > > Test:
> > > public void Can_get_list_of_assets()
> > > {
> > > using (UnitOfWork.Start())
> > > {
> > > AssetRepository repository = new AssetRepository();
>
> > > var assets= repository.GetAssets();
>
> > > Assert.IsNotEmpty(products);
> > > }
>
> > > }
>
> > > GetAssets in repo:
> > > public IList<AssetBase> GetAssets()
> > > {
> > > return base.Session
> > > .CreateCriteria<AssetBase>()
> > > .List<AssetBase>();
> > > }
>
> > > Mapping:
> > > <class name="AssetBase" table="Assets" abstract="true">
> > > <id name="_persistenceId" column="Id" access="field"
> > > unsaved-
> > > value="00000000-0000-0000-0000-000000000000">
> > > <generator class="guid.comb" />
> > > </id>
>
> > > <property name="Name" not-null="true" />
>
> > > <property name="Description" type="StringClob">
> > > <column name="Description" sql-type="text" />
> > > </property>
>
> > > <joined-subclass name="Product" table="Products">
> > > <key column="Asset" />
>
> > > <property name="IsPremium" not-null="true" />
> > > <property name="Grade" not-null="true" />
>
> > > <map name="_prices" access="field"
> > > table="ProductPrices">
> > > <key column="Product" />
> > > <index column="PackagingSize"
> > > type="Int32" />
> > > <element column="Price" not-null="true" />
> > > </map>
> > > </joined-subclass>
>
> > > <joined-subclass name="Program" table="Programs">
> > > <key column="Asset" />
>
> > > <map name="_prices" access="field"
> > > table="ProgramPrices">
> > > <key column="Program" />
> > > <index column="NumberOfAttendees"
> > > type="Int32" />
> > > <element column="Price" not-null="true" />
> > > </map>
> > > </joined-subclass>
> > > </class>
>
> > > Thanks in advance,
> > > Ryan
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/nhusers?hl=en.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.