Questions tagged [buddy-class]
15 questions
9
votes
4 answers
Validation does not work when I use Validator.TryValidateObject
DataAnnotations does not work with buddy class. The following code always validate true. Why ?
var isValid = Validator.TryValidateObject(new Customer(), Context, results, true);
and here is the buddy class.
public partial class Customer
{
…

ashraf
- 1,319
- 2
- 16
- 24
4
votes
2 answers
DataAnnotation attributes buddy class strangeness - ASP.NET MVC
Given this POCO class that was automatically generated by an EntityFramework T4 template (has not and can not be manually edited in any way):
public partial class Customer
{
[Required]
[StringLength(20, ErrorMessage = "Customer Number -…

JK.
- 21,477
- 35
- 135
- 214
4
votes
2 answers
Required attribute in Buddy Class not working with Entity Framework 5 and ASP.NET
My database has a field that is not nullable, but can contain an empty string. When I try to save the record using connection.SaveChanges(), I get an exception saying "The MyField field is required."
I have created a BuddyClass as follows, but I…

Jim S
- 1,069
- 3
- 10
- 17
2
votes
1 answer
MVC3 Buddy Classes, ViewModels and Validation
I'm currently working on my first MVC project which is nothing more than a glorified blog for my own learning purposes. I started out with a database-first approach as I had no idea code-first even existed at that point. That's left me with some…

John H
- 14,422
- 4
- 41
- 74
2
votes
1 answer
DataAnnotation in WPF with Database first approach - how to move data annotations to buddy class incl. IsValid function
As it is shortly described in the topic: How to move all DataAnnotations from model to MetaData model in order not to wipe it out when updating edmx?
In another words I would like to have data annotation secure and not get rid of with each update of…

Tomasz Strączek
- 91
- 8
2
votes
1 answer
Getting buddy class information?
I'm trying to read buddy class metadata information for usage outside of the normal asp.net mvc 2 validation process. I thought it would be as simple as saying:
DataAnnotationsModelMetadataProvider metadataProvider = new…

John Farrell
- 24,673
- 10
- 77
- 110
1
vote
1 answer
DisplayAttribute not work in Dotnet Core buddy class
I've been trying to attach a DisplayAttribute to a field in my buddy class in Dotnet Core, but it not appears in my View. for example in View display "Title" instead "عنوان".
The two classes are linked via ModelMetadataType.
where is wrong?
orginal…

Morteza Jangjoo
- 1,780
- 2
- 13
- 25
1
vote
1 answer
How can I auto-generate DataValidation "Buddy" classes from my database in ASP.NET MVC3?
I have a website that has the views generated directly from objects created by Entity Framework. After reading this blog by Scott GU it seems the best way to get DataValidation to work is to have started with POCO objects instead. (search for the…

makerofthings7
- 60,103
- 53
- 215
- 448
1
vote
1 answer
What exactly is a Buddy Class and how do I use it to add Annotations to an existing class?
I've seen the term "Buddy class" used as an 'answer' to questions like "how can I add annotations to a partial class in another file" but these answers assume I know what a Buddy Class is, and the code examples assume I understand how/why this…

Mr. Boy
- 60,845
- 93
- 320
- 589
1
vote
2 answers
Do Buddy Classes only work for DataAnnotations?
Do buddy classes only work for dataannotations, or for any attribute? I've been trying to attach a ColumnAttribute to a field in my buddy class, but it appears that it doesn't get processed in the original class. The two classes are linked via…

Alex
- 75,813
- 86
- 255
- 348
1
vote
1 answer
Creating a Entity Framework Buddy Class in a VB.NET MVC Application to extend validation
In the entity Data Model I have the following complex type
Partial Public Class…

user1833564
- 11
- 2
0
votes
1 answer
MVC .net core: Validator.TryValidateObject is not validating attributes, defined in a buddy class
We used DB-first approach to generate models in a .NET core application. DataAnnotations were put in a "buddy" metadata class so as to avoid writing in an autogenerated file. When controller calls TryValidateModel, all works well, Name property is…

berserker
- 104
- 5
0
votes
2 answers
Add LINQ Auto-Generated Value Marker [Column(IsDbGenerated=true)] in Buddy Class
is it possible to decorate a field of a LINQ generated class with [Column(IsDbGenerated=true)] using a buddy class (which is linked to the LINQ class via [MetadataType(typeof(BuddyMetadata))]) ?
My goal is to be able to clear and repopulate the LINQ…

Alex
- 75,813
- 86
- 255
- 348
0
votes
1 answer
Buddy Class MemberInfo not returning custom attributes
EDIT: I was able to get what I needed via this code, which pulled the list of buddy classes associated to my type - t is the type of my non-buddy class.
MetadataTypeAttribute[] metaAttr =…

tarun713
- 2,177
- 3
- 17
- 31
0
votes
1 answer
create buddy class for auto generated desgner.cs with Database first
I want to create a buddy class, for the autogenerated Designer.cs in Datafirst Entity Framework, to implement validations with dataannotations.
The solutions I found on google contains examples with simple properties like
public int…

VirendraTamrakar
- 1
- 1