3

I have the class generated by Entity Framework called Person.cs which is in namespace Project.Model.

I have then put a new folder in the project called Extensions, added Person.cs inside there and set the namespace for this file to Project.Model.

After doing this, I get the error:

Type 'Project.Model.Person' already defines a member called 'Person' with the same parameter types.

What am I doing wrong? I need to extend EF Person.cs to have other properties.

Here is my code for the extended Person.cs.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.Model
{
    public partial class Person
    {
        public Person()
        {

        }
    }
}
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
dynamicuser
  • 1,522
  • 3
  • 24
  • 52

1 Answers1

4

You should remove default constructor from Person class:

public partial class Person
{
    // add properties here
}

Your partial class is a part of the same class, so as with any other classes definitions - no member can be defined twice, including constructor. If you'll go to Person class generated by EF, you will see that it already has default constructor (EF uses it for navigation properties initialization).

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • 1
    Is this a good place to put those extensions though? Or should I instead create domain models in the business layer and use automapper to map between them? – Chazt3n May 08 '15 at 01:39