Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6717405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:50:52+00:00 2026-05-26T08:50:52+00:00

I develop a simple MVC3 CRUD application – simple controllers / views, which uses

  • 0

I develop a simple MVC3 CRUD application – simple controllers / views, which uses WCF service for CRUD data access.

The WCF uses EF4.1 with DbContext, and simple CRUD-style methods: ListEntities, GetEntity(ID), AddEntity (entity), DeleteEntity(ID)

If I develop the MVC application directly with EF, code first, I can annotate properties in the entity classes with validation attributes, and the MVC application will automatically recognize validation errors and report them in the UI when I try to save and a validation error occurs (e.g. a required field is not set).

But in my application I don’t use this approach and I face two problems:

  1. My entities in the WCF are generated from the EDMX, which in turn was also generated from the database. So I cannot actually add to them any data validation annotation attributes, because they’ll vanish as soon as the entities will be regenerated from the EDMX. Is there any solution to this?

  2. Since my client (MVC app) does not share the data contract classes with WCF (for clear separation), but instead it is generated form service reference, even if I find a way to add data annotation attributes to server-side data contract classes, will they be recognized and recreated when the data contract proxy class is created on client side?
    So how could I made the MVC application to use client side validation and error message reporting for validation failures when binding to entities exposed by WCF service as data contracts?

One idea I have is, on client side, to create derived classes for all entities exposed as data contracts, and apply annotation attributes to them to desired properties. But this doesn’t looks like a good solution to me, because with this I create a logic “coupling” between UI client and the WCF service / data layer (forcing UI to know about data more than it should do – by putting BL logic in client).

Can anyone give me some suggestions on how to handle those this situation?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:50:52+00:00Added an answer on May 26, 2026 at 8:50 am

    1: Yes you can add validation using the System.ComponentModel.DataAnnotations.MetaDataType.

    I answered this question at MVC Partial Model Updates

    2a: What you can do is create a seperate Class Library Assembly that contains all the interfaces (with or without additional MetaDataTypes) and use that on both the WCF service and the MVC application. After you add the reference to your MVC application, when adding the WCF Service reference, you can match the WCF Service DataContacts directly to the interfaces in the Assembly. One Caveat is that both the WCF service and MVC application are dependant on the Assembly (some might consider this tightly coupled) but this should be ok because you are only tightly coupling at the interface level, and whether or not you choose to allow VS to recreate it’s own interfaces/classes or reuse what you already created in the Assembly it boils down to the same thing in my opinion.

    2b: If you decide not to use a Class Library, I’m pretty sure that the service reference classes are partial, and you can simply create another .cs file with partial classes and add the interfaces as I described in part 1 to the partial classes.

    Update

    I am currently using Entity Framework to access my database. Entity Framework, like WCF References, classes are Auto-Generated classes will look something similar to:

    [EdmEntityTypeAttribute(NamespaceName="MyNameSpace", Name="Info ")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Info : EntityObject
    {
        public static Info CreateInfo (global::System.Int32 id)
        {
            Info info= new Info ();
            info.Id = id;
            return info;
        }
    
        public string Name { get; set; }
        public string FavoriteColor { get; set; }       
    
        // etc etc
    
    }
    

    In a separate file with the same namespace as the previous partial class, I have created:

    [SomeAttribute1]
    [AnotherAttribute2]
    public partial class Info: IInfo
    {
    }
    

    So now my auto-generated class is not only based on an Interface I created IInfo so the actual methods are not exposed (because my datatier in MVC returns interfaces), but it also has Attributes (for Data Annotations or whatever).

    What I would suggest is instead of putting your data annotations directly on your WCF Service reference class is to use the MetedataType DataAnnotations. This allows you to separate the actual data object with the data annotations validations. Especially helpful if you want to use the same data class with different validations based on whatever (maybe administrators don’t have to have a valid favorite color).

    For example:

    public interface NormalUser
    {
      [Required]
      string Name { get; set; }
      [Required]
      string FavoriteColor { get; set; }
    }
    
    public interface AdminUser
    {
      [Required]
      string Name { get; set; }
      string FavoriteColor { get; set; }
    }
    
    [MetadataType(typeof(INormalUser))
    public class NormalUserInfo : Info { }
    
    [MetadataType(typeof(IAdminUser))
    public class AdminUserInfo : Info { }
    

    In this example we have two different classes NormaUserInfo and AdminUserInfo which both have different validations. Each of them have inherited from Info so they are valid models that can be passed into the WCF Service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop a simple orm which performs CRUD functionality.Shold i use reflection?
Sometimes I need to develop a simple database application using MS Access Databases. I`ve
i develop a asp.net mvc3 shop application which is multi tenant. Each customer (around
I want to develop a simple iPhone application which can record the external sounds,
My i have to develop simple window based iphone application. In my first screen
I am trying to develop a simple application in C# to count the number
I new in the android developing. I want to develop simple application that will
I develop a simple Google Maps application. I need just to place one marker
I must develop a simple web application to produce reports. I have a single
i'm trying to develop a simple Hello World web service using Axis2 v1.5, Tomcat6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.