Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Generated code> Typed collections
 

Pages: 1
Generated code
Typed collections
Page:1/1 

  Print all messages in this thread  
Poster Message
nbrake
User



Location:
Hamburg, Germany
Joined on:
18-May-2008 22:27:47
Posted:
30 posts
# Posted on: 18-May-2008 22:45:44.  
Hi there,

I am using V2.5, TwoClasses2005WithValidator, March 28th build, on .NET 2.0, running against SQL Server 2005

My actual case

I have a class called MyImportEntity. MyImportEntity maps a db-1:n relationship to a table called report through a collection of called MyReportEntity.

An instance of MyImportEntity, import, has a member called Report, and this member is of the type EntityCollection<ReportEntity>, and not EntityCollection<MyReportEntity>.

My question is: why aren't the subclasses used in defining the collections? At run time, the members of the collection are of the subclass type.

Why am I asking this?

I defined a number of methods using collections of the subclasses. Now I am unable to call such a method with import.report, sind report is EntityCollection<ReportEntity> and not
EntityCollection<MyReportEntity>.....


Best regards

brake
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
7627 posts
# Posted on: 19-May-2008 06:52:28.  
Hi brake,

If I understand you well, at your DB you have something like:

     MyImport -(1:n)> Report

This is mapped to LLBLGen as:

     MyImportEntity -(1:n)> ReportEntity

Now you create a ReportEntity subclass at code (MyReportEntity). Then you want to use such class instead of the original ReportEntity.

Why not just to extend the ReportEntity adding your own methods and properties?

Anyway, this should be done via casting:
Code:
import.Report = someMyReportEntity.

((MyReportEntity) import.Report).MyCustomMethod();



David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
nbrake
User



Location:
Hamburg, Germany
Joined on:
18-May-2008 22:27:47
Posted:
30 posts
# Posted on: 19-May-2008 09:05:07.  
Hi Daelmo,

I am already using the 2 classes solution, which means I mostly use the subclasses generated by LLBLGen. In the generated subclasses, the entity collections (that map 1:n relationships) doen't use the subclass, but the original class. In my example, MyImport has members of the type Report (an import consists of a number of reports), instead of MyReport. During runtime MyReport elements are returned, but not while compiling.

This is the code generated

Code:

/// <summary> Gets the EntityCollection with the related entities of type 'MBReportEntity' which are related to this entity via a relation of type '1:n'.
/// If the EntityCollection hasn't been fetched yet, the collection returned will be empty.</summary>
[TypeContainedAttribute(typeof(MBReportEntity))]
public virtual EntityCollection<[b]MBReportEntity[/b]> MBReport


import.Report is an EntityCollection of type EntityCollection<MBReportEntity>. It is also not possible to up cast EntityCollection<MBReportEntity> to EntityCollection<MyMBReportEntity>, as vs would not take that.

My question is, why aren't the members the map to 1:n relationships defined as subclasses, something like?
Code:
[TypeContainedAttribute(typeof(MBReportEntity))]
public virtual EntityCollection<[b]My[/b]MBReportEntity> MBReport




Best regards



  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
34715 posts
# Posted on: 19-May-2008 18:34:49.  
You're using adapter I think (I think David assumed you're on selfservicing Wink).

The thing is that EntityCollection<SomeEntity> isn't a supertype of EntityCollection<MySomeEntity>, even though MySomeEntity is a subtype of SomeEntity.

This means that if the fields were defined with a different mapping, they created a new hierarchy parallel to the parent one, so instead the collection is kept (as MySomeENtity is storable in a collection of type EntityCollection<SomeEntity>). The factory of the collection is set to the My... variant, and the attribute on it tells the databinding code that the type in the collection is the My variant..


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
nbrake
User



Location:
Hamburg, Germany
Joined on:
18-May-2008 22:27:47
Posted:
30 posts
# Posted on: 20-May-2008 10:01:02.  
Of course you are right, I am using adapter, and should have mentioned this!

That was the explaination I needed!

Thank you for the reply!
Nasser
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.