validating with EF v4 and WCF data services

Topics: Validation Application Block
Dec 22, 2010 at 2:57 PM

for demonstration purpose i am using northwind database. i modelled all tables with designer then i added a WCF application to use wcf data service.

 public class NorthwindDataService : DataService<NorthwindEntities >
    {
       
        public static void InitializeService(DataServiceConfiguration config)
        {
          
             config.SetEntitySetAccessRule("*", EntitySetRights.All);
             config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    }

 

then i created a console app which will be used for validating user inputs. i configured app.config at console app side to validate ProductName between 3-10 and UnitPrice between 0-99999. but when i validated the object, it is always true according to this code sample.

  context = new NorthwindEntities(new Uri("http://localhost:49074/NorthwindDataService.svc/", UriKind.Absolute));

            Product p = new Product();       


            p.ProductName = "a";//must be 3-10
            p.UnitPrice = -12;//must be pozitive

            ValidationResults results = productValidator.Validate(p);
            

            if (!results.IsValid)//always valid
            {

                foreach (var item in results)
                {
                    MessageBox.Show(item.Key+":"+item.Message);
                }

            }

how can i use entityframework with VAB??

Dec 23, 2010 at 6:07 AM

Hi

As far as I know there is no any explicit relationship between EF and VAB. Anyway, could you post your config or how have you implemented your validator from your VAB implementation for us to be able to look closely on this. Thanks.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 23, 2010 at 9:15 AM
i have added complete sample project. i hope this will help..

2010/12/23 AvanadeSupport <notifications@codeplex.com>

From: AvanadeSupport

Hi

As far as I know there is no any explicit relationship between EF and VAB. Anyway, could you post your config or how have you implemented your validator from your VAB implementation for us to be able to look closely on this. Thanks.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Read the full discussion online.

To add a post to this discussion, reply to this email (entlib@discussions.codeplex.com)

To start a new discussion for this project, email entlib@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
Olcay ŞEKER

Yazılım Geliştirme Eğitmeni / Software Development Trainer
BilgeAdam Bilgi Teknolojileri Akademisi

Dec 23, 2010 at 1:26 PM

Hi,

Based from the sample you have sent, the reason why the validation result is always true is because you actually configured a different type from your config (Model.Product)

        <type name="Model.Product" defaultRuleset="Validation Ruleset"
            assemblyName="Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">

and validating the other type (Client.NorthwindService.Product) in your form's code behind. That's is why the validator doesn't fire. Instead, what you can do is to configure the correct type in your configuration to have it in synch with your code.

        <type name="Client.NorthwindService.Product" defaultRuleset="Product Ruleset"
            assemblyName="Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">

HTH. 

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com