Question

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()
        {

        }
    }
}
Était-ce utile?

La solution

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).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top