LINQ Custom Entity Object Validation Support

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I am working through this tutorial :

http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-upd
ating-our-database.aspx

and trying to get this code to work :

using System;

public partial class Order
{
partial void OnValidate()
{
if (RequiredDate < OrderDate)
{
throw new Exception("Deliver date is before order date!");
}
}
}

But I am getting this error :

No defining declaration found for implementing declaration of partial
method 'Order.OnValidate()'

Can anybody help with this?
 
Hi Mike,

You're getting the error message because the implementing partial OnValidate
signature you're using isn't the same as the defining partial OnValidate
that is in the Order class. You should use the following signature instead:

partial void OnValidate(System.Data.Linq.ChangeAction action)
{
if (action == System.Data.Linq.ChangeAction.Update)
{
if (RequiredDate < OrderDate)
{
throw new Exception("Deliver date is before order
date!");
}
}
}

This was a change made during RTM and Scott's code was written prior to
that.

Joe
http://www.csharp-station.com
 
Back
Top