0

I know this question is asked many times, but I couldnt get a clear picture of what I need.

I have a WPF application which I need to redo using 3- Tier approach.

I have used Entity Framework for creating datamodel and using Linq queries for querying the data.

objCustomer = dbContext.Customers.Where(c => c.CustCode == oLoadDtl.CustNo).First();

I use Linq queries where ever I need in the program to get records from the database.

So, I just would like to know which all stuff comes under DAL, Business logic and UI layers.

Also, how do I separate them?

Can the entity datamodel considered as a DAL?

Is it a better idea to put the entity model in a separate class library?

H.B.
  • 166,899
  • 29
  • 327
  • 400
sony
  • 1,453
  • 3
  • 35
  • 79

1 Answers1

1

It's better to create special class called DataAccess to encapsulate EntityFramework-invokes. For business logic you can create model classes, they will use DAL if needed. Other details depend on what your application should do. For example:

//DAL
public class DataAccess
{
    public static void GetCustomerByNumber(int number)
    {
        var objCustomer = dbContext.Customers.Where(c => c.CustCode == number).First();
        return objCustomer;
    }
}

//Models
public class Customer
{
    public string Name { get; set; }
    public int Number { get; set; }

    public Customer GetCustomerByNumber(int number) 
    {
       return DataAccess.GetCustomerByNumber(number);
    }

    public void ChangeProfile(ProfileInfo profile)
    {
       //...
    }
}

Main things are extensibility, re-usability and efficiency of your solutions.

Sasha
  • 1,676
  • 1
  • 16
  • 18
  • Does that mean that I need to create classes for each database table and each CRUD operation? – sony Aug 01 '12 at 10:52
  • Methods, not classes :) For example, 20 entities - 4 or more CRUD operations for each entity -> about 80 static methods. Modern developer tools allow to manage it easily. If amount of CRUD methods is more than 6 for some entity I create nested class in DataAccess class which will operate this entitiy. In other words, I do it for large groups of semantically similar methods. – Sasha Aug 01 '12 at 11:02