How to create a business model wrapper for a universal approach to the database?

I am currently facing a performance issue when creating POCO objects from my database. I am using Entity Framework 4 as an OR-Mapper. At the moment, the entire application is a prototype.

Suppose I want to have some business objects, such as Printer or Scanner. Both classes inherit from BaseClass called Product. Business classes exist.

I am trying to use a more general approach to the database. I do not want to create tables for "Printer" or "Scanner". I want to have 3 tables: one is called Product, and the other is Property and PropertyValue (which stores all the assigned values ​​to a specific Product).

At my business level, I am creating a specific object like this:

public Printer GetPrinter(int IDProduct)
{
  Printer item = new Printer();
  // get the product object with EF
  // get all PropertyValues
  // (with Reflection) foreach property in item.GetType().GetProperties
  // {
  //   property.SetValue("specific value")
  // }
  return item;
}

This is how the EF model looks: enter image description here

It works great. So far I am doing performance tests to extract multiple sets.

I created a prototype and improved it several times to increase productivity. This is still far from use. I take 919ms to create 300 objects that contain only 3 properties.

The reason for choosing such a database project is the creation of a common database. Adding new properties should only be done in the business model.

Am I just too stupid to create an efficient way to extract xx objects, or is my approach completely wrong? As far as I understand OR-Mapper, they basically do the same thing?

+3
source share
2 answers

, ORM. , ORM, , buisness -. ORM -. - , ORM. , :

  • ( )
  • ( )
  • ( )

IMO, , , -, ORM EF.

, -. , - = .

, . PropertyValue Property , ExtendedProperties, . Product , . .

+5

-, , POCOs. 4 ? , - POCO, T4 Generated POCOs/Context POCOs/Context. , POCOs ( 15 ), POCO Entity Framework. , ... MSSQL , ?

+1

All Articles