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

  • SEARCH
  • Home
  • 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 4020524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:14:20+00:00 2026-05-20T10:14:20+00:00

There are a lot of examples on how to create your own model. Mark

  • 0

There are a lot of examples on how to “create your own model”. Mark them with DataAnnotations. Scott Guthrie explains how to validate your model when using an ORM. What I don’t find is when your model is actually coming in from an external DLL. How do you validate it?

Example:

/* Class coming in from an third-party DLL file. */
public class Person
{
    public string Name{get;set;}
    public int Age {get;set;}
}

The solution I am thinking of: Inherit the external class and then apply [MetadataType] to the inherited class.

[Metadata(typeof(Person2_Validation))]
public class Person2:Person{}

public class Person2_Validation
{
    [Required,Stringlength(50,ErrorMessage="Name required"]
    public string Name{get;set;}

    [RegularExpression("([0-9]+)")]
    public int Age
}

Is there a better way?

  • 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-20T10:14:21+00:00Added an answer on May 20, 2026 at 10:14 am

    You could create a model and use a Mapper (like AutoMapper or EmitMapper or ValueInjecter) to map between your objects, and validate against the mapped model.

    When you need to transfer the object back you can map between your model to the recieved model.

    This is very similar to a ViewModel approach in ASP.NET MVC.

    So it’s something like this:

    Class A (the class from the DLL)
    Class B (your model)

    You set all your annotations on B, and create whatever properties you need.

    What you use is B. When you get something from the repository/source you map (copy all relevant values) A=>B and send it (let’s say as a model in a View).

    When you receive B back you validate it, and then map it the other way B=>A, and send it to the repository/service.

    BTW: I would recommend using this approach even if model A was YOUR class.

    Why use ViewModels instead of Domain Models in Views.

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

Sidebar

Related Questions

There are a lot of examples on the internet of reading files but I
I see there are lot's of examples in Ext JS where instead of actually
There's a lot of questions about bookmarks but none of them answers my question:
There are a lot of posts to show to create a virtual floppy image
So, we often create posts with videos in them and mark up the page
I know that there are lot's of questons on this, but all seem to
I know there a lot of similar questions to this, but I didn't find
There are a lot of blogs saying that a hasOwnProperty check should be used
There are a lot of questions about didRegisterForRemoteNotificationsWithDeviceToken but they all sidestep a very
There are a lot of iOS apps in the iTunes Store that, upon launch,

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.