0

Not too sure if that was the right way to word the question but i'm currently getting my head around MVC.

I have multiple Entity Data Models(I'm not sure this is best practice, but it seemed logical), however only one is working as its presenting the error of

'Asaurus.Models.ConnectionString' already defines a member called 'ConnectionString' with the same parameter types..."

These are the two classes

1:

    public partial class ConnectionString : DbContext
{
    public ConnectionString()
        : base("name=ConnectionString")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<TABLE1> TABLE1 { get; set; }
}
}

2:

public partial class ConnectionString : DbContext
{
    public ConnectionString()
        : base("name=ConnectionString")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<TABLE2> TABLE2 { get; set; }
}
}

Is it possible to avoid this conflict?

Thanks in advance, James

1 Answer 1

3

Not too sure if that was the right way to word the question

Well, considering you didn't actually ask a question in the title, I would say that no.. it's not. Apart from that, you really need to understand that asp.net MVC and entity framework are two entirely different technologies that just get used together, so asking a question tagged with mvc but it's really about EF will gain you less response than if you tag it correctly. In addition, you should actually read the tags you apply. They have actual meanings, which are described clearly in their desriptions... In particular, the [Model-View-Controller] tag says this in it's description:

Model–View–Controller (MVC) is an architectural pattern used in software engineering. For Microsoft ASP.NET MVC, please use [asp.net-mvc] tag instead.

So if you want to be a good member of the community, learn to read what the website tells you.

Now, on to your question... First, why are your EDM's called "ConnectionString"? You should be naming them after their intended purpose. It's not wrong to include multiple models if you are using at least EF 6 (earlier versions had difficulties with this), but your problem here is that you called both of your models the same thing. You should delete one and recreate it with a more meaningful name.

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

1 Comment

Okay thanks :) In regards to the EDM's, I have actually called something useful, however visual studio pre-populated all the names and stuff, and it seemed to work the first time(hopeing that no naming collisions would occur). If I create them both again can they both use the same named connection string?

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.