1

I am currently writing a WCF data service that is meant to extract data from any database in a predefined standard structure.

I was thinking of using POCO entities. I can design my entities on EF designer and generate the POCO classes from it but the bit I struggling to understand is how to write data access layer and inject it into the DBContext.

So for each different database, I'll have a data access layer that will retrieve data from a database or even an xml file and map the data to my POCO entities.

I am not sure if this is achievable at all.

The POCO classes will be my standard structure to expose to the world. I can't see anywhere to write custom sql queries to extract data from a DB and then set the data in the POCO classes. The POCO classes do not match any of the database tables so I explicitly need to map database fields to the POCO classes but I am not sure how to do this in Entity Framework using POCO.

I believe POCO is the write option but struggling on the data access layer and mappings from database to POCO classes.

All the samples I have seen talk about connecting the EF to an existing database directly. Meaning the EF structure has to match the structure of the database. What I want is a single EF/POCO structure that can retrieve data from multiple databases. These databases do not have the same structure but I need to manually retrieve data from these databases and transform it into the POCO classes structures. I do not necessarily want to get data from multiple databases at once but from a single DB but want to use the same model for any database - So I guess I have to write a custom DAL for each database which gets the data from a DB and transform the data into the POCO model structure.

I would really appreciate if anyone could help me.

By the way I am new to EF so please be patient.

Nasir
  • 59
  • 11
  • 1
    we had a similar discussion in this [thread][1] [1]: http://stackoverflow.com/questions/8102149/should-a-repository-return-ienumerablet-iqueryablet-or-listt – np-hard Nov 17 '11 at 19:18
  • Thanks np, I'll have a look and get back to you. – Nasir Nov 18 '11 at 09:15

1 Answers1

1

Have you followed this tutorial which shows you how to create model classes from a DB and query against them?

Also here is a great tutorial on using EF code-first, in which you build your POCO classes first, and it generates the DB for you. Great read :).

Jack
  • 9,156
  • 4
  • 50
  • 75
  • Thanks Jack, Yes I have seen those links but these talk about generating from existing tables or creating classes then generating data from your classes. My situation is a little different in a sense that I already have all the database with different tables but they may be storing the same data, what I want to do is have a standard structure i.e. POCO classes and then get data from any data source and populate it in my POCO classes. – Nasir Nov 17 '11 at 18:31