views:

16

answers:

1

I have a class "MyEntity", which does not have a default constructor (well, it does, yet it is not suitable for use).

I have a form with a DataGrid, which has a cool feature for creating new rows.

Problem: DataGrid cannot create new object when no parameterless constructor is defined.

Question: is there a way to provide the DataGrid with a Func that would construct the new object (= some factory method like CreateObject)? Or is there some other solution?

PS Adding a default constructor is not an option - it is not suitable for my purposes. POCO in EF4 requires objects to be created through a context factory class (calling CreateObject).

A: 

Wrap your MyEntity class in another class (MyEntityWrapper) with a default constructor and databind the grid to a collection of MyEntityWrapper objects. Put it in a VM to keep you view (the grid) and model (the collection of MyEntity object) clean.

Wallstreet Programmer
Well, seems like this is the only option for now. Thanks for the help :)
Jefim