one or more Entity models for one database for entity framework? - entity-framework

When use entity framework for DAL tier, VS 2010 can create edmx for each database.
Question:
If I have a database with many tables, should I create only one edmx for all tables or mutiple edmx files? for example, maybe all security tables for one edmx file, other tables for another edmx file. If there is more than one, then in other tiers, there will have more then on ObjectContext in code for business logic.
Which one it the best solution for this case?

I've done this before when experimenting with AdventureWorks. If you have a large database with lots of tables, and the tables are segmented into separate schemas (like the Purchasing, Sales, HumanResources schemas in AdventureWorks) then it may work well to create multiple models. They don't have to be separate schemas- any two groups of related tables where there are no relations between the groups would work.
You'd want to make sure that you include all related tables in each model so that you don't have to try to join entities across models.

Related

CREATE POSTGRESQL Entity Relationship Model

I desperately need your help. I have database tables IN POSTGRESQL which I need to create an ER Model for them. My challenge is creating relationships among the tables. I know this might be alot of work but I just need help on creating relationships among the tables, what column names should I use and all that . Here is an image of the tables in the database

Does EntityFramework allow you to map a single model to multiple tables?

My project will allow users to create and work on multiple projects, so most of my tables will accordingly have a ProjectID column.
However one of those tables, let's call it ProjectData will become very large very quickly, as each project can have hundreds of thousands of rows. To me it makes more sense to have a table for each Project, thus 001Data, 002Data, etc.
Does EntityFramework allow for such single model -> multiple table mappings? Perhaps it would be better to have separate databases for each project, but that too provides its own set of challenges.

laravel model best practice

Hi I'm using laravel in my current project. I thought its recommended to create a model for each database table to get the best out of eloquent's Relationships
somewhere in my Database I have this mapping table to map records from table A to table B (many to many)
should I create a model for my mapping table ? what is the best practice in such cases?
This question is best answered from an architetural point of view:
Models are made to represent entities. Mapping Tables do not store entities but information about relationships between entitites (many-to-many). Therefore, creating models for mapping tables does not make much sense.
Laravel offers a concepts called pivot-table for this kind of usecase, which is very well documented in the docs.

Map multiple tables to a single entity dynamically

I have some tables which should add to my database every year and name of databases contains the year (like sell2005) and iv'e written some ef queries on these tables ,and queries can only be on a single entity (like sell2005) but what should i do when sell2006 or sell2007 add ? how can i manage them with that single query which iv'e written before?
thank you.
There is no easy way. EF is simply not tool for this scenario. For EF you must have "single table" so you must either use partitioning with one real database table partitioned by year or you must build a view on top of these tables.
The problem is that in EF you have strict relation between classes and tables. You cannot have single class mapped to multiple tables even if they are exactly same (except inheritance which is not solution for you). So the workaround would require to have multiple SSDL/MSL mappings - one for each table and construct correct context instance with correct mapping for every query. As I know dynamic changes of mapping are not possible (except modifying SSDL/MSL files before using them).

Enity Framework for existing enterprise database

I am working on creating a service layer for a large sql server database (2008 R2) that is currently the backend for a winforms POS application with strongly typed datasets.
I think WCF is the way to go, and at first glance it seemed EF 4 was a good choice but now I'm having my doubts. Here is what I have found:
The stored procedure mapping isn't that great. I have hundreds of stored procs that I want to reuse. Most of them wouldn't return an 'entity' so the stored procs would have to be mapped to a complex type. Many of the procs use dynamic sql or temp tables so EF can't figure out what complex type to crete. Many of the procs return multiple result sets. I've read that EF extensions have a way to map stored procs with multiple result sets, but only for entities, so that doesn't help me.
Large models are a problem. There doesn't seem to be a good way to handle large entity models. The workaround of creating smaller models isn't that desirable and splitting the model loses design support, am I missing something?
EF mappings only go so far. The stored procs that I want to reuse return projections or information from many tables into a result set. There doesn't seem to be a way to map these results into entities, am I wrong? I've read about combining results from 2 table into 1 entity, but that only works if the tables have the same primary key.
Are people using EF in large scale existing databases? If not what would you recommend?
I've used EF on large scale databases, but as you say, the support for SPs as you have got is not great. That's not specifically a failing of EF per-se - ORMs in general work on the same principle and have the same "limitation".
If you have lots of SPs and are mapping them to datasets, you'll have to do lots of work even without SPs in terms of no longer referencing datasets and referencing your domain model types through your system, so you'd need to have some way to map your SPs to your domain model and back anyway.