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 7028879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:27:55+00:00 2026-05-28T00:27:55+00:00

How can I add annotations/attributes to my classes or methods of classes in my

  • 0

How can I add annotations/attributes to my classes or methods of classes in my model, generated from my Model.edmx file? The reason I’m asking this is because every time I add an annotation to a class Model.Designer.cs, this annotation disappears when I make changes to my Model.edmx file through the designer.

More specifically, I am looking for a way to add the AllowHtml annotation to a specific property within one of my model classes, and make it stay there even after messing around with it in the model designer view.

Here’s the controller code. The Content property of the Segment class is the one causing my controller to crash when being populated with HTML.

    [FacebookAuthorize(Permissions = AuthenticationController.ExtendedPermissions, LoginUrl = "/Authentication/LogOn?ReturnUrl=~/Segment/Contribute")]
    [HttpPost]
    [ValidateInput(false)]
    public ActionResult Contribute(int id, string content)
    {

        var container = new ModelContainer();

        var parent = container.SegmentSet.SingleOrDefault(s => s.Id == id);

        var segment = new Segment();
        segment.Content = content; //this crashes with HTML data.
        segment.Owner = AuthenticationController.Authentication.GetUser(container);
        segment.TimeModified = DateTime.UtcNow;
        segment.TimePosted = DateTime.UtcNow;

        container.AddToSegmentSet(segment);

        if (!parent.Children.Contains(segment))
        {
            parent.Children.Add(segment);
            segment.Parent = parent;
        }

        container.SaveChanges();

        return RedirectToAction("Index", "Home");
    }
  • 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-28T00:27:55+00:00Added an answer on May 28, 2026 at 12:27 am

    You can use MetadataTypeAttribute to extend your classes:

    [MetadataType(typeof(MyEdmxClassExtension))]
    public partial class MyEdmxClass { }
    
    public class MyEdmxClassExension
    {
        [AllowHtml] // Add the attributes you want to find on your property
        public string ThePropertyYouWantToExtend { get; set; }
    }
    

    This code goes in a separate file than the one generated or you will lose it, too, of course.

    Edit

    In response to the comments below, I believe you have two questions. Your original question is answered using the MetadataTypeAttribute and, for the second, you should probably open another question.

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

Sidebar

Related Questions

Can we add annotations to the decelerations instead to the getter methods. I'm used
Ruby can add methods to the Number class and other core types to get
I know I can add a icon to the Resources.resx file of a project
How i can add the multiple values from a datagrid to textbox in C#?
How can I add annotations of all the contacts in my custom group, in
I have a model for a User generated by EF from an existing database:
what can a problem that data annotation attributes are not rendered? web.config <appSettings> <add
I'm trying to add annotations to NSMutableArray annToLoad so I can later perform [mapView
I can add and remove the last line in my dynamic form and calculate
I know that I can add a HintPath to an external DLLs to help

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.