Click here to Skip to main content
12,894,700 members (60,891 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 27 Aug 2012

MVC3 Buddy Classes issue with validation attributes

, 27 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
MVC3 Buddy Classes issue with validation attributes.


When you create a Buddy class to add validation attributes to your code-generated models, it doesn't behave as expected.

The generated code:

// <auto-generated>
//     This code was generated from a template.
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;

namespace Entities
    [DataContract(IsReference = true)]
    public partial class Book: IObjectWithChangeTracker, INotifyPropertyChanged
        #region Primitive Properties
        public int Id
		rest of class 

Here is the Buddy class:

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Entities.Custom
    public partial class Book

    public class BookMeta
        public string Name { get; set; }

        public double Price { get; set; }


The problem is that the namespaces are different, Entities.Custom in the buddy class and Entities in the generated one.

Just make sure both are equal and everything should be fine.

Points of Interest

Hope this is useful to anyone who encounters this problem, I wasted an hour looking for a solution on the web till I finally had the inspiration to unify the namespaces.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Omar Gameel Salem
Software Developer
Australia Australia
Enthusiastic programmer/researcher, passionate to learn new technologies, interested in problem solving, data structures, algorithms, AI, machine learning and nlp.

Amateur guitarist/ keyboardist, squash player.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 27 Aug 2012
Article Copyright 2012 by Omar Gameel Salem
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid