I have a library function that returns a list of domain objects from a Linq query.
IList<Apple> getApplesByCriteria( ... );
I bind the DataSource property of a DataGridView to the result of this function. Everything works well. Now I want to manipulate properties of Apple. The presentation domain object (UIApple) is different than the original domain object (Apple), where
UIApple map( Apple apple );
converts one to the other.
If I create an intermediate class - UIApple, what do I need to do to persist editing of the DataGridView back t开发者_开发知识库o the database? I learned that adding [Browsable(false)]
can hide a collumn. However, I'd prefer not to 1) pollute the domain objects with UI concepts; 2) change the auto generated source code.
I created UIApple which is backed by Apple and contains all the manipulation code.
For example:
class Apple {
// generated by Visual Studio
public int Color { ...
}
class UIApple {
private Apple _domain;
public string Color
{
get { if(_domain.Color == 0) return "Black"; }
set { if(value == "Black") _domain.Color = 0; }
}
// hide all unwanted attributes
}
To persist at the end of editing,
UIApple uiApple;
// some editing through UI
// to commit -
db.SubmitChanges();
精彩评论