Click here to Skip to main content
14,241,566 members
Rate this:
Please Sign up or sign in to vote.
See more:

I am using 3 layered architecture in c# winforms.

I have created 3 different projects as these layers (UI, BLL, DAL)

BLL referenced in UI.
DAl referenced in BLL.

I already have the database of having around 150 tables.
Some tables having more than 100 fields.

I want to pass data from UI to BLL to DAL and back as well.

If i create classes for each table in BLL, that will be a mess for me as its lot of fields.
And if i created classes in BLL, i can pass from UI to BLL. But then how to pass to DAL
with out creating another model in DAL?.

Will EF work here for me?
If it works, shall i create the EDMX as a separate project? or simply in DAL?.

Another case is, my company has 3 out lets. Each location is having different database,
but same structure.
If i create EF, i need to select the database there na. But will it work at my another outlet, when i
compile it and run the setup at the outlet?.
The database names and paths may be different in each locations.

Please advise.

What I have tried:

i have tried using parametric field values passing to DAL from BLL, but its a hectic job. Need a quicker solution to it without creating another model in DAL.
Updated 29-Feb-16 16:26pm
Frank R. Haugen 29-Feb-16 18:55pm
I belive you have written you qestion inside a code tag ;-)
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use EF however you like. You can create a new project or you can use it in an existing one (may be with a tweak with your existing code).

Just to give you a hint, EF uses something called DbContext. Even you have hundreds of tables in your database, you can setup your DbContext with just a handful of related tables.

Referring to your other problem, EF typically reads its connection string from a .config file. So, if you set the connection string correctly and your database servers have accessibility over the Internet, you can connect with any database server by changing the connection string. And if the database schema is same, it will work too.
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can reuse the same model provided that the model is defined in the DAL (assuming that UI use BLL and BLL use DAL) and that the model is adequate.

Using same model might be easier if you have data-bound editable models... I would think that it depends a lot on the application.

If the BLL layer essentially return full records and your application is mainly based on CRUD, then I would think that a common model is adequate.

Generally, I think you would create the EDMX file in the DAL layer.
jim1972 1-Mar-16 8:22am
if i create EDMX within DAL layer (which is in a separate project), how i pass the BLL class into this EDMX?.
Philippe Mori 1-Mar-16 9:00am
You don't. BLL layer will use DAL classes if you want to reuse same classes.

You can always create an extra assembly for the EDMX model but since generated classes are tied to the database framework you use (EF), you don't gain much by separating them if your purpose is to avoid defining similar classes (or interface) multiple times (and you don't plan to use other databases).

jim1972 1-Mar-16 16:30pm
ok. but, how can i transfer data from UI into EDMX which created in DAL layer, as DAL is not referenced in UI.
Philippe Mori 1-Mar-16 17:07pm
Either create a forth assembly or reference the DAL (since we alreay assume you want to avoid creating distinct view models).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100