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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:05:05+00:00 2026-05-18T05:05:05+00:00

I am trying to use data annotations to validate my Entity Framework models using

  • 0

I am trying to use data annotations to validate my Entity Framework models using partial classes.

I was told in this article (MSDN), that the partial class should be in the same namespace as the data model. My data model is located in EntityFrameworkDataProvider, so my partial class which is located in MyApp.Backend.Models looks like this:

using System.ComponentModel.DataAnnotations;

namespace EntityFrameworkDataProvider
{
    [MetadataType(typeof(ItemMetaData))]
    public partial class Item { }

    public class ItemMetaData
    {
        [ScaffoldColumn(false)]
        public object CreateDate { get; set; }

        [Required]
        public string DisplayName { get; set; }

        [Required]
        public string Description { get; set; }
    }
}

I validate the model in my controller class like this:

[HttpPost]
public ViewResult Edit(Item item)
{
    if (!TryUpdateModel(item))
    {
        return View(item);
    }

    return View("Details", item);
}

It compiles without errors. However, when trying to edit an item this error is what I get:

Compiler Error Message: CS0433: The type ‘EntityFrameworkDataProvider.Item’ exists in both ‘long-path.DLL’ and ‘long-path.DLL’

I guess the Item class is being compiled twice or something. How should this error be prevented?

  • 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-18T05:05:05+00:00Added an answer on May 18, 2026 at 5:05 am

    Your controller action is wrong. You should never use action parameters and TryUpdateModel on the same type because it will insert the error messages twice in the model state. Your action should look like this instead:

    [HttpPost]
    public ViewResult Edit(Item item)
    {
        if (!ModelState.IsValid)
        {
            return View(item);
        }
        return View("Details", item);
    }
    

    As far as the compiler error message you are getting you haven’t provided enough information so that I can help you. Make sure that this Item class is not defined in different locations and that it is indeed partial in every single .cs file you encounter it. I suspect that somewhere you have an Item class defined which is not partial. What you should be aware of as well is that if this Item class is defined in a separate assembly, even if it is marked with partial, once compiled, the notion of partial no longer exists. Partial classes work only within the same assembly.

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

Sidebar

Related Questions

I'm trying to use the DataAnnotationsModelBinder in order to use data annotations for server-side
I'm trying to use some data from a PlanPlusOnline account. They only provide a
I'm trying to use NHibernate for data access, and I have 2 simple entities
I am trying to use the new DATETIMEOFFSET data type in SQL 2008 but
I am trying to use the ASP.NET Dynamic Data features to generate CRUD scaffolding
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint
I'm trying to use rusage statistics in my program to get data similar to
I am trying to use the following code to write data into an excel
I am trying to use jQuery's ajax functionality to update data from a web
I am trying to use GetThemeFont to read the font data from a visual

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.