views:

812

answers:

2

Hello,

I am getting this error when clicking the Delete button / link in a GridView control

LinqDataSource [DataSource] does not support the Select property when the Delete, Insert or Update operations are enabled

I don't really understand why I'm getting this error because I have already done the same thing on a different webpage in my site, however the table that the data is read from in that case does not have any foreign keys, this one does. Is that why I am getting the error?

If it matters, the AutoGenerateDeleteButton property is set to True, and I am using a linqdatasource to retrieve the data from the database.

Any input would be appreciated :)

Thanks!

A: 

In the end I had to select all of the data (using the * option in the DataSource wizard), then remove the columns that I didn't want to display in the GridView. This might be a little inefficient, but it worked.

Hewie
A: 

Just ran into this problem and found a solution and explanation elsewhere.

The Select statement results in an Anonymous type wich may not be mapped when the Delete/Update/Insert statement should be generated by the LinqDataSource. The source Table (linq) is used for generating the metadata for the database operation.

We will have to live whith the small performance loss when needing to retreive all the columns in the data source, but gets some work done behind the scenes. Me like.

And, if you use GridView, you need to specify the DataKeyNames property to the data source's primary key(s).

Crystal clear!? ;)

JERKER