Extending partial method on DataContext causes action not to be passed to database - by Ben Hall _UK_

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


0
0
Sign in
to vote
ID 289561 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 7/29/2007 3:11:13 PM
Access Restriction Public

Description

Hello,

I've just been looking in Partial Methods and Linq (http://blog.benhall.me.uk/2007/07/partial-methods-in-linq.html) and found either a bug or something which is unclear and confusing.

On the Data Context, if I implement and of the Insert,Update,Delete partial methods then when I try and perform that action on the database and the SQL is never generated. However, the partial method is called.   If we use the Console.out as the Linq's output source or SQL Profiler this shows no sql queries being executed.

If we have this code in a partial datacontext class: 
 partial void UpdateOrder(Order instance)
        {
            Console.WriteLine("UpdateOrder");
        }

Then doing a simple update such as this would not work:
List<Order> table = query.ToList<Order>();
table[0].ShipName = DateTime.Now.ToString();
db.SubmitChanges();

Now, if this is not a bug and is by design then it could be a lot clearer.  I don't like the fact that a method could either be a hook or override functionality without any clear indication to which one it is.

As mentioned in the post, something like partial override void .....() would be better and demostrate that something is being changed and not extended. 

Just an idea..... hope this is useful to you.

Ben Hall
Sign in to post a comment.
Posted by Microsoft on 8/2/2007 at 6:14 PM
Ben,

Thank you for taking the time to try out new LINQ to SQL feature in beta2 and providing feedback. The partial method is an override for the update operation rather than a pre-update method. It provides an opportunity to do completely custom update logic and calling a stored procedure. There is also an easy way to accomplish what you were looking to do. Right before/after the Console.WriteLine(...) statement, you can call
this.ExecuteDynamicUpdate(instance);

Thanks again for trying and giving feedback.

Dinesh Kulkarni
Sr. Program Manager
Developer Division
Microsoft
Posted by Microsoft on 7/30/2007 at 1:59 AM
Thanks for your feedback. We have reproduced this bug on Visual Studio 2008 Beta 2, and we are sending this bug to the appropriate group within the Visual Studio Product Team for triage and resolution.

Thank you,
Visual Studio Product Team.
Posted by Microsoft on 7/29/2007 at 9:00 PM
Thank you for your feedback. We are currently investigating. If this issue is urgent, please call support directly (see http://support.microsoft.com). Thank you, Visual Studio Product Team.