6

I am using Entity Framework 4.1 and generating my classes using the database first approach. I have a an EDMX file in my solution.

I am trying to add attributes to my classes using the MetadataTypeAttribute approach which seems to be the recommended way of doing this outside of editing the T4 template, however, I cannot seem to get it to work because I keep getting this compile error:

'Patient' is an ambiguous reference between 'PatientManagementSystem.Patient' and 'PatientManagementSystem.Models.Patient'

Here is the code I am using:

[MetadataTypeAttribute(typeof(PatientMetadata))]
public partial class Patient
{
}

public class PatientMetadata
{

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

}

Is this error happening because I don't actually have classes for this because I am doing Database first and everything in the EDMX?

Thanks! Flea

4
  • 1
    What's the namespace for your edmx and for the class above? They should match. Commented Apr 27, 2013 at 21:47
  • Adam, the namespace for the EDMX is empty (Also, it's in a class library project that is apart of my MVC project) and the namespace for my class is: PatientManagementSystems.Models Commented Apr 28, 2013 at 1:07
  • Adam, that was the problem. I had to fix the namespaces and now it seems to be working. If you want to copy what you said and put it as the answer I will mark it for you. Thanks! Commented Apr 28, 2013 at 1:32
  • thx, added answer below Commented Apr 29, 2013 at 19:24

1 Answer 1

4

Make sure both are in the same namespace. Since it's a partial class, the class you are modifying must also be in the same namespace or it isn't the same class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.