views:

89

answers:

2

If I have a LinqDataSource without EnabledDelete, EnabledUpdate, EnabledInsert, it works fine, but as soon as I add those properties to the data source, I get the error:

No parameterless constructor defined for this object.

A: 

As the error indicates, you need to provide a parameterless constructor for the class.

public class MyClass
 {
   public MyClass()
   {
     // This is the parameterless constructor
   }
   // rest of the class members goes here.
  } 

The system requires a parameterless constructor when it is required to create instances of a class automatically. It cannot determine the meaning of the parameters of your other constructors so it depends on this constructor.

Even if your constructor does nothing it will still work, though you may want it to provide useful defaults for your class properties.

Vincent Ramdhanie
I am not sure which class it is talking about though?
Xaisoft
A: 

Here is an answer that helped me solve the issue from the MSDN forums:

LinqDataSource requires a default constructor on the DataContext. If you are working in a web application or website project, the Linq to SQL designer should have created a default constructor and connection string for you when you dragged tables from the database onto the design surface.

Did you create your DataContext and drag tables onto the design surface from a webapp or website project? Open the Lib.NorthwindDataContext class that was generated and see if it has the default constructor.

If you really want, you could also use LinqDataSource without the default constructor by handling the ContextCreating event and providing your own context instance.

YeahStu