I am learning the Entity Framework and I decided to create a simple console application that uses Entity framework with two tables.
I've created two tables: http://wstaw.org/w/LrL/
I have appropiate classes for the database.
This is the code.
The Contact class.
public class Contact
{
public int ContactID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Address> Addresses { get; set; }
}
And the Address class.
public class Address
{
public int AddressID { get; set; }
public string Street { get; set; }
public string City { get; set; }
}
Visual studio shows Following Errors.
Error 3 Missing partial modifier on declaration of type 'MyEntityPOCO.Contact'; another partial declaration of this type exists Contact.c 8 19 MyEntityPOCO
Error 4 Missing partial modifier on declaration of type 'MyEntityPOCO.Address'; another partial declaration of this type exists Address.cs 8 19 MyEntityPOCO
Error 1 Running transformation: Please overwrite the replacement token '$edmxInputFile$' with the actual name of the .edmx file you would like to generate from. MyEntityPOCO\Model1.tt 1 1
How might I resolve these errors?
The partial keyword is used to declare a class in more than one code file. It is explained here: http://msdn.microsoft.com/en-us/library/wa80x488.aspx
What has happened in your case is that you have a class decorated with the partial keyword (the one created in the yourmodel.edmx.cs file by EF), and another class with the same name in the same namespace.
Normally with two classes with the same name in the same namespace (without the partial keyword) you would get a class name conflict exception. In this case, because one of the two classes is marked as partial, the C# compiler generates the error that you are seeing.
Suggested solution: Search your code for the other class, determine how it got there and either rename it, move it to a different namespace or also mark it with partial if it is meant to be the same class.