LINQ Custom Entity Object Validation Support

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?
 
J

Joe Mayo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top