3

I'm trying to convert an old project c# to asp net core and to the EF core 2.0 and I can't find the EntityConnectionStringBuilder.

public string GetEntityConnectionString(string databaseName, string metadata)
{
    string providerName = "System.Data.SqlClient";
    string providerString = GetConnectionString(databaseName);


    System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder entityBuilder =
    new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder();

Error CS0234 The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

2 Answers 2

2

That's because EF Core does not support what was known "database first" approach of older EF versions, so there are no edmx files, and so there is no use for EF specific connection strings (metadata=res:... < this kind of connection strings). From that it follows that there is no use for EntityConnectionStringBuilder class, which is used to create such connection strings.

So when porting, just remove your whole GetEntityConnectionString method and use your GetConnectionString instead, together with UseSqlServer, UsePgsql and similar methods.

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

Comments

0

You may set connection on Context. Try override OnConfiguring method:

    public class CommonDbContext : DbContext
    {
        public CommonDbContext(DbContextOptions<CommonDbContext> options)
            : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Data Source=127.0.0.1;Initial Catalog=DBName;User ID=user;Password=pwd;Connection Timeout=60");
        }
    }

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.