LINQPad should warn if a user function will override a DataContext method
I wrote out some scripts that was intended to query a database, update some rows, and save them back. When I attempted to run them, it seemed like the changes wouldn't go through. After some long debugging sessions and major alterations to my script, I eventually found out that the name of some methods was causing the conflicts.
Let's say one of the tables I was updating was called:
I think that LINQPad should be able to detect this situation and at least warn about it. There might be legitimate cases where we'd want to actually override it, but I would have expected the override modifier would be required.
Let's say one of the tables I was updating was called:
MyTable
. I happened to create a function that had the signature:
void UpdateMyTable(MyTable)It wasn't public/protected, there was no override, there was no warnings so I expected no issues. I eventually ended up renaming that method to
FixMyTable(MyTable)
and everything worked out.I think that LINQPad should be able to detect this situation and at least warn about it. There might be legitimate cases where we'd want to actually override it, but I would have expected the override modifier would be required.
Comments
I probably could have checked the stack trace as I was debugging too, it might have revealed more. But in my attempts to determine what was wrong, I moved the calls to
SubmitChanges()
in and out of methods. When I put it in the update method and stepped through, it immediately jumped to the top of my update method.Something like: I don't know if it would be appropriate for me to post the exact code, but I'll come up with something representative of how it was set up.
and the output:
note the "no update" in the output
In the end, the table doesn't get updated. I could rerun the query multiple times and the table will still be untouched. There are no further errors.
You can see more if you look at the reference source (see here or here)
I'm not sure sure what the advantage of 'duck-typing' is in this case, but one big disadvantage is that you do not get compiler warnings if you happen to use one of those special names for your own methods and if you are not aware of these special names (and I admit I wasn't until I read this thread), then you can end up with unexpected behaviour.