Newbie ... where to start ..

Aug 9, 2011 at 3:58 PM

Dear All,

I just got in here from a problem to validate navigation properities.

Is there a simple example to start with .. Simple insturction form ...

Regards

 

Developer
Aug 9, 2011 at 4:00 PM

Hi,

Did you have a look at the EntityGraphCarParkExample?

Aug 11, 2011 at 3:44 AM

Hello Mdej,

Yes I did, actually I don't know how to this in my development, by another mean, I have a simple edmx generated using EF4.0, where I have two classes (header & detail) the header has a navigation proerity of the detail, I then add a custom validation to the metadata generated class for the header on the detail navigation prop.

for example:

	[MetadataTypeAttribute(typeof(IGL_dailysummery.IGL_dailysummeryMetadata))]
	[CustomValidation(typeof(CustomDailyValidation), "ValidateDuplicateAccountId")]
	public partial class IGL_dailysummery
	{

		// This class allows you to attach custom attributes to properties
		// of the IGL_dailysummery class.
		//
		// For example, the following marks the Xyz property as a
		// required property and specifies the format for valid values:
		//    [Required]
		//    [RegularExpression("[A-Z][A-Za-z0-9]*")]
		//    [StringLength(32)]
		//    public string Xyz { get; set; }
		internal sealed class IGL_dailysummeryMetadata
		{
			// Metadata classes are not meant to be instantiated.
			private IGL_dailysummeryMetadata()
			{
			}
			[CustomValidation(typeof(CustomDailyValidation), "ValidateDailyDate")]
			public DateTime daily_date { get; set; }
			[Key]
			public decimal daily_number { get; set; }

			public short discriptor { get; set; }

			[Include]
			[Association("daily_summary", "period_id,subsidiary_id,month_number,daily_number,discriptor", "period_id,subsidiary_id,month_number,daily_number,discriptor")]
			public EntityCollection<IGL_daily> IGL_daily { get; set; }

			public IGL_discriptor IGL_discriptor { get; set; }

			public IGL_poststatus IGL_poststatus { get; set; }

			public IGL_subsidiarybase IGL_subsidiarybase { get; set; }

			public decimal? manual_number { get; set; }
			[Key]
			public decimal month_number { get; set; }

			public string notes_1 { get; set; }

			public string notes_2 { get; set; }
			[Key]
			public int period_id { get; set; }

			public int? post_status { get; set; }

			public int? resource_id { get; set; }
			[Key]
			[CustomValidation(typeof(CustomDailyValidation), "ValidateSubsidiary")]
			public int subsidiary_id { get; set; }

			public decimal user_id { get; set; }
		}
	}

 

as you can see, I have the "ValidateDuplicateAccountId" as entity validation and I have this validator in a .shared.cs file as follows:

public static ValidationResult ValidateDuplicateAccountId(IGL_dailysummery dailysummery, ValidationContext validationContext)
{
	var dups = dailysummery.IGL_daily.GroupBy(i => i).Where(g => g.Count() > 1).Select(g => g.Key);
	foreach (var d in dups)
		return new ValidationResult("AccountID is duplicate error!!", new[] {"account_id", "IGL_dailysummery"});

	return ValidationResult.Success;
}

 

Although the validation is not executed at the client-side when I hit submitchanges it get executed but I can't get the details.

How can I implement the EntityGraph in this scenario

Regards

Developer
Aug 11, 2011 at 7:51 AM

Hi,

Reading your post, I get the impression that you don't need the validation stuff from RiaServicesContrib, but that you can do with the standard validation mechanism of RIA services.

Jeff Handley has written a couple of very instructive blogs about data validation in RIA services. Checkout http://jeffhandley.com/archive/2010/09/22/RiaServicesStandardValidators.aspx.

He also wrote a blog that deals with asynchronous validation. I think that is what you are looking for. You can find it here: http://jeffhandley.com/archive/2010/05/26/asyncvalidation-again.aspx.

Good luck,

Merijn

Aug 12, 2011 at 12:57 PM

Hello Mdej,

I have read many posts for Jeff, very good indeed ... But I can' find there the solution of my issue.

I have debug the Method and check the Navigation property inside the Dailysummary, each time is empty ...is it something wrong with my way of adding IGL_daily entity to the collection or what.

Please advice.

Regards

Developer
Aug 18, 2011 at 3:37 PM

Hi,

Did you try removing the ValidationContext parameter of your custom validation method ValidateDuplicateAccountId?

In Jeff's blog on entity-level validation he mentions that parameter is not needed. Could it be that this prevents your code from being executed?

Kind regards,

Merijn