0

I have a partial class Table1 which is generated by EF and I have created another partial class Table1 in the same namespace with the same name with some custom properties.

EF has created a parameterless constructor and I need to have one more constructor with some parameters in my custom partial class Table1. But my code is complaining:

member names cannot be the same as their enclosing type

Is there a workaround for this?

The EF generated code for Table1 looks like:

public partial class Table1
{
    public Table1()
    {
        this.something= new HashSet<something>();
    }
}

And my custom code for partial class Table1:

public partial class Table1
{
    public void Table1(string test)
    {
        //do something
    }
}
BJ Myers
  • 6,617
  • 6
  • 34
  • 50
user3557236
  • 289
  • 1
  • 4
  • 14

1 Answers1

1

You do not need to put a return type on a constructor. You just need

public Table1(String test){ }

Not

Public void Table1(String test){

}

Your compiler is complaining because it thinks you are trying to declare a regular method with the same name as your constructor. Drop the void and it because a second constructor.

Jim Fallin
  • 236
  • 1
  • 6