卡在CTP5仅代码消息:无法确定连接类型'System.Data.SqlClient.SqlConnection'的提供程序名称。 [英] Stuck on CTP5 Code-Only Message: Unable to determine the provider name for connection of type 'System.Data.SqlClient.SqlConnection'.

查看:38
本文介绍了卡在CTP5仅代码消息:无法确定连接类型'System.Data.SqlClient.SqlConnection'的提供程序名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用CTP 5构建演示应用程序以呈现仅代码功能。

Trying to build demo app to present Code-Only functionality, using CTP 5.

有两个版本的应用程序:在我的MVC版本中,我可以返回数据就好了来自现有的NorthwindEF数据库。 但是,在我的Web窗体版本中,我收到以下错误:

Have two version of app: In my MVC version, I can return data just fine from existing NorthwindEF database.  However, in my Web Forms version, I get following error:

无法确定连接类型为"System.Data.SqlClient.SqlConnection"的提供程序名称。

任何建议都将不胜感激!

Any suggestions would be appreciated!

这是DbContext类:

Here is DbContext Class:

    public class CodeOnlyContext : DbContext
    {
        public DbSet<Customer> Customers { getset; }
        public DbSet<Order> Orders { getset; }
        public DbSet<OrderDetail> OrderDetails { getset; }
        public DbSet<Product> Products { getset; }
        public DbSet<Category> Categories { getset; }

        public CodeOnlyContext()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["EFConnectionString"];
            Condition.Requires(connectionString).IsNotNull("Must include connection string");
            Database.Connection.ConnectionString = connectionString.ToString();
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            //Default length for nvarchar is 4000 characters
            modelBuilder.Entity<Customer>().Property(p => p.CompanyName).HasMaxLength(50);
            modelBuilder.Entity<Customer>().Property(p => p.ContactName).HasMaxLength(30);

            //modelBuilder.Entity<Order>()..Property(p => p.CustomerId).


            //Default property for dateTime type is 'not null'
            modelBuilder.Entity<Order>().Property(p => p.OrderDate).IsRequired();
            modelBuilder.Entity<Order>().Property(p => p.RequiredDate).IsRequired();
            modelBuilder.Entity<Order>().Property(p => p.ShippedDate).IsRequired();

            modelBuilder.Entity<OrderDetail>().HasKey(x => new { x.OrderId, x.ProductId });

        }
    }

以下是查询:

        public List<Customer> RetrieveCustomerByLocationByQueryMethod(string location)
        {
            using (var ctx = new CodeOnlyContext())
            {
                //-- Demonstate 'Query Syntax'  (Keep in mind: Querying conceptual model, not the database)
                var querySyntax = from c in ctx.Customers
                                  where c.Region == location
                                  orderby c.CompanyName
                                  select c;

                return querySyntax.ToList();
            }
        }

以下是连接字符串:

  <connectionStrings>
    <add name="CodeOnlyConnect" connectionString="Data Source=.;Initial Catalog=CodeOnlyTest;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

 

 

 

推荐答案

糟糕。 ..

Oops...

这是上面例子的正确连接字符串:

Here is correct connection string for above example:

    <add name="EFConnectionString" connectionString="Data Source=.;Initial Catalog=NorthwindEF;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />


这篇关于卡在CTP5仅代码消息:无法确定连接类型'System.Data.SqlClient.SqlConnection'的提供程序名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆