1

The entity framework documentation states that I can use a named parameter when supplying my connection string:

public class BloggingContext : DbContext 
{ 
    public BloggingContext() 
        : base("name=BloggingCompactDatabase") 
    { 
    } 
}

I normally don't normally bother with the named parameter:

public TspDbContext()
    : base("ViktorVooey") { }

but I thought I'd give it a go just for confirmation:

   public TspDbContext()
            : base("name=ViktorVooey") { }

and it fails saying

Keyword not supported : name

This is on EF6. So I'm sort of stuck between not really caring but still wanting to know "what's up with that" all the same.

2 Answers 2

2

I came across your post because I had the same error. The MSDN documentation for EF 6 DbContext explicitly states that the 'name=' part of the constructor string parameter is supported and means:

The name can also be passed in the form 'name=myname', in which case the name must be found in the config file or an exception will be thrown.

In other words the "name=" prefix forces EF to only look for a config file entry for the connection string.

So you should check that the value you pass with "name=" is actually a name key value in your config file.

For example, in the config file:

<add name="MyContextName" connectionString="blah blah"/>

In the constructor:

public MyContext()
            : base("name=MyContextName")
Sign up to request clarification or add additional context in comments.

Comments

0

For me this turned out to be an issue with Resharper. I suspended Resharper, built and the error went away.

After I restarted Resharper the error stayed away.

Comments

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.