Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:44:23+00:00 2026-06-03T07:44:23+00:00

This is a custom ORM thing we’re working on. It’s not awesome, but it’s

  • 0

This is a custom ORM thing we’re working on. It’s not awesome, but it’s what we’ve decided on doing.

Basically the base class Entity is extended by any number of other classes. These child classes must be annotated using attributes.

There is one particular type of attribute which is a collection. The attribute defines the sub-type of the collection.

eg.

public class Blah2 : Entity
{
    ...
}

public class Blah : Entity 
{
    [QRel(Type = typeof(Blah2)]
    public IEnumerable<Blah2> blahs;
}

Loading these child objects is easily done, but they are loaded as the base type, Entity.

Via reflection, so at run time I have, in the ORM manager:

  • The type marked in the attribute: Type t
  • The field info of blahs: FieldInfo f
  • The entity instance of type Blah: i
  • A generic loaded list containing a set of Blah2 instances: List<Entity> l

I need to create a list lt using the derived type t (i.e. dynamically create and fill a List<Blah2>) and assign it to the field of type Blah:

var lt = ...
f.SetValue(i, lt);

Notice that because this is all done via reflection the types of the objects I have are: t -> Type, i -> Entity, f -> FieldInfo, l -> List<Entity>.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:44:25+00:00Added an answer on June 3, 2026 at 7:44 am

    I would suggest that you create a helper class, Helper<T> which does the allocation of the properly typed generic list, and fills the list with the items. You could cache an instance of the helper class in order to reduce the cost of reflection.

    abstract class Helper
    {
        public abstract IEnumerable<Entity> CreateList(IEnumerable<Entity> loadedList);
    }
    
    sealed class Helper<T> : Helper where T : Entity
    {
        public override IEnumerable<Entity> CreateList(IEnumerable<Entity> loadedList)
        {
            return new List<T> (loadedList.OfType<T> ());
        }
    }
    

    To create an instance of the Helper<T>, just do this:

    var helperType = typeof (Helper<>).MakeGenericType (t);
    var helper = Activator.CreateInstance (helperType) as Helper;
    

    and then to allocate and fill the list of Blah2 based on the generic list:

    var lt = helper.CreateList (l);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my config file I've defined custom Entity Manager: parameters: doctrine.orm.entity_manager: class: Strict\UserBundle\Entity\Manager\MyEntityManager Is
I have this custom textbox that I am working on and I can use
I am leaking memory on this: my custom class: + (id)vectorWithX:(float)dimx Y:(float)dimy{ return [[[Vector
This is my custom model binder. I have my breakpoint set at BindModel but
I'd like to create a few custom annotations for an Entity class, i've come
A web service return to my flex3 client this custom exception: <SOAP-ENV:Fault xmlns:ro=urn:Gov2gLibrary xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/
Is there a standard method I can use in place of this custom method?
I have a ListView which contains custom rows. This custom row has following UI
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
Check this code (My Custom Keyboard): -(IBAction) updateTextBackSpace:(id)sender { if([txtview.text length]>0) { NSString *deletedLastCharString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.