LinqDataSource does not support the Select propert

2019-04-28 10:10发布

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 :)

3条回答
倾城 Initia
2楼-- · 2019-04-28 10:47

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!? ;)

查看更多
劫难
3楼-- · 2019-04-28 10:52

Sure, the problem is that you must to include the primary key in the data source configuration and then, mark as invisible this primary key.

查看更多
放荡不羁爱自由
4楼-- · 2019-04-28 10:53

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.

查看更多
登录 后发表回答