Annotations are implemented with partial classes called metadata classes. You use metadata classes when you want to annotate generated entity classes, but do not want to lose those annotations when the entity class is regenerated. You specify a metadata
class by using the MetadataTypeAttribute attribute.
pantonis
Member
328 Points
260 Posts
Metadata classes
Feb 22, 2012 08:24 AM|LINK
Hi,
I'm using MVC3 and I'm trying to create Metadata classes for validation. I'm also using Linq to SQL. My question is:
In my dbml.designer.cs file a propertt(database field) has the following attribute:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "client_name", DbType = "NVarChar(150)")]
In my metadata class do I still need this attribute along with the Required, Range etc.. ?
Thanks
Please mark this post as answer if it helped you solve your problem
adeelehsan
All-Star
18287 Points
2740 Posts
Re: Metadata classes
Feb 22, 2012 08:48 AM|LINK
Generally you need to create a partial metadata class with MetadataType attribute. See the following links:
http://diegworld.blogspot.com/2011/05/using-dataannotations-to-validate.html
http://msdn.microsoft.com/en-us/gg592096
http://www.codeproject.com/Articles/249452/ASP-NET-MVC3-Validation-Basic
MCPD ASP.NET 4.0 and 3.5, MCTS WSS, MOSS, SharePoint 2010, MCT
Microsoft Community Contributor Award 2011
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Metadata classes
Feb 22, 2012 08:49 AM|LINK
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "client_name", DbType = "NVarChar(150)")]
Do not add those to metadata files.
Annotations are implemented with partial classes called metadata classes. You use metadata classes when you want to annotate generated entity classes, but do not want to lose those annotations when the entity class is regenerated. You specify a metadata class by using the MetadataTypeAttribute attribute.
Weera
pantonis
Member
328 Points
260 Posts
Re: Metadata classes
Feb 22, 2012 09:21 AM|LINK
Is there any way to set the MetadataTypeAtribute dynamically and not in the dbml file?
Please mark this post as answer if it helped you solve your problem
thaicarrot
Contributor
5132 Points
1465 Posts
Re: Metadata classes
Feb 22, 2012 09:36 AM|LINK
What you need is third party tool for dynamically generate Metadata. But I haven't seen any tool for MVC at the moment.
You can add DomainService then it will create MetaData file for you after that just delete DomainService or use it as BLL and DAL for your APP.
Weera