{"id":27,"date":"2008-01-18T22:42:11","date_gmt":"2008-01-18T20:42:11","guid":{"rendered":"http:\/\/jsiegmund.wordpress.com\/2008\/01\/18\/linqdatasource-not-deleting-records\/"},"modified":"2013-04-18T18:54:05","modified_gmt":"2013-04-18T17:54:05","slug":"linqdatasource-not-deleting-records","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2008\/01\/linqdatasource-not-deleting-records\/","title":{"rendered":"LinqDataSource not deleting records"},"content":{"rendered":"<p>I ran into a small problem using the LinqDataSource as a datasource for a GridView or ListView (the new 3.5 ListView features quite nice functionality, with an insert-capable grid!).<\/p>\n<p>I had set up a datasource with a ListView bound to it\u00a0which had a button per row to call the &#8216;Delete&#8217; command. The other commands seemed to work fine (insert, edit) but the delete command didn&#8217;t do anything. Just a postback; no exception, no deletion, nothing.<\/p>\n<p>After a lot of debugging, I found out I had set the primary key of my Linq object to be &#8216;readonly&#8217;. I had done this to prevent users from altering the PK and thereby breaking the database. Since the primary key was a generated\u00a0uniqueidentifier anyway, I\u00a0didn&#8217;t want my users to mess with it.<\/p>\n<p>Anyway; after removing this setting (thus setting it <strong>not<\/strong> to be read-only), it suddenly deleted records just as I wanted it to.<\/p>\n<p>The designer&#8217;s description for the Read Only setting is: &#8220;Controls whether an a set accessor is generated.&#8221;. That&#8217;s because each column\/members get&#8217;s its own property with a get\/set accessor. I&#8217;m not quite sure why this disables the possibility of deleting an object. Perhaps because you can&#8217;t create the object without setting it&#8217;s primary key, which makes sence. But then again; how is\u00a0the object populated from the database with the correct private key and why is that method not used to populate it again on postback? Better yet: I would suppose the entire object is stored somewhere in the viewstate between postbacks so the primary key should be in there somewhere, right?<\/p>\n<p>I&#8217;m not quite sure about why, but I do know you&#8217;d better leave your primary key not be read-only, unless you never want to delete that object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into a small problem using the LinqDataSource as a datasource for a GridView or ListView (the new 3.5 ListView features quite nice functionality, with an insert-capable grid!). I had set up a datasource with a ListView bound to it\u00a0which had a button per row to call the &#8216;Delete&#8217; command. The other commands seemed<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-r","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/27"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}