Creating Entities by theire name

Posts   
 
    
msjonathan
User
Posts: 9
Joined: 05-Jan-2010
# Posted on: 05-Jan-2010 15:40:24   

Hej,

I have the following the name of some entities in an Enum (strings). The enum is used for databinding to a dropdownlist. After the user selects a desired Entity, i want to create automatically a new entity of the selected type. Has anyone an idea how to solve this, I am a newbie @LLBLGEN simple_smile

Greetz Jonathan

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 05-Jan-2010 21:38:00   

The simplest method is to use the EntityFactoryFactory generated class to return an EntityFactory for the type of entity that you want to create, and then use this to create the Entity for you.

The EntityFactoryFactory class is in the DBGeneric\EntityFactories folder.

Matt

msjonathan
User
Posts: 9
Joined: 05-Jan-2010
# Posted on: 06-Jan-2010 08:18:33   

MTrinder wrote:

The simplest method is to use the EntityFactoryFactory generated class to return an EntityFactory for the type of entity that you want to create, and then use this to create the Entity for you.

The EntityFactoryFactory class is in the DBGeneric\EntityFactories folder.

Matt

Thank you very much for your'e help but when I do EntityFactoryFactor.GetFactory(Type) I have to give a type, but i have only a string with the name. Can you give a code example?

Greetz Jonathan

msjonathan
User
Posts: 9
Joined: 05-Jan-2010
# Posted on: 06-Jan-2010 08:27:59   

Actually the meaning of my program is, The user selects an Entity and from that entity I display all the fields as rows in a Grid. Ex: I have a drop down list with 3 Entities (Person, Visitor and employee) I a user selects person, i want to fetch all Fields and display them.

Maybe I can do this without generating an entity?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Jan-2010 09:54:32   

Can you use the EntityType enum for the values of bound to the DropDownList?

msjonathan
User
Posts: 9
Joined: 05-Jan-2010
# Posted on: 06-Jan-2010 10:07:48   

That's my problem, not all entities should appear in the drop down-list. Because I'm writing an import, and not all tables are able to import.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Jan-2010 10:56:35   

You may use string concatenation and reflection or Activator.CreateInstance() to creeate the entityFactory from the strings you are using.

msjonathan
User
Posts: 9
Joined: 05-Jan-2010
# Posted on: 06-Jan-2010 13:10:50   

Thank you for you're help wink