views:

719

answers:

1

Using Entity Framework the DataLayer is created (DataLayer.dll) The DataLayer.dll contains the data-objects. I need to add some business logic to the class 'person'.

Yes, i know, that I can use partial classes, to add business logic. But in this case (using partial classes) we need to implement it in DataLayer.dll!

I need to uses the BusinessLayer.dll

So the business layer is created (BusinesLayer.dll)

in BusinesLayer.dll we have the file myPerson.cs

using DataLayer;

namespace Businesslayer
{
public class myPerson : DataLayer.Person

public Property String FullName()
{
  get {return this.Firstname + " " + this.LastName}
}

}

Actually I need to show the data in the grid, like this

 var data=context.Person;
 dataGridView1.dataSource = data;

Yes, the context.Person returns a list of Person-Objects and so in the Grid the Column 'FullName' is not available

How to create the List on myPerson-Objects?

+1  A: 

First of all, if you're only creating FullName in order to display it in a grid, then I'd say it belongs in the UI layer, not the business layer.

Second, you don't need inheritance for this. You can use delegation. Give your UIPerson class an instance of Person in the constructor. Then, for each property of Person that you want to expose to the grid, do something like this:

public DateTime BirthDate
{
   get {return _person.BirthDate;}
   set {_person.BirthDate = value;}
}

ReSharper can do this for you, or you can use some other tool or do it by hand. You then get to add your FullName property the same way.

John Saunders
The Property 'FullName' is only an example. Yes, the Business Object needs more complicated business logic and different additional Properties. Follwoing your solution: to show the List of UIPerson in a grid:var data=context.Person;foreach person in data { listUI.add(new UIPerson(person)) }
Well, more "var listUI = from person in data select new UIPerson(person);"
John Saunders