使用asp net 5访问IBM db2数据库

时间:2016-04-01 21:35:44

标签: entity-framework-6 asp.net-core entity-framework-core ado.net-entity-data-model db2-400

我需要将我的ASP Net 5应用程序与IBM Db2数据库连接。

我找到了这些nuget包:

https://www.nuget.org/profiles/IBMDB2EF

我遵循了本教程:

https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/sample_ef7_application_for_ibm_data_servers?lang=en

但这不起作用。

我的project.json

=SUM(SUMIFS(Accomplishment points, range-of-acronyms,"SNE", range-of-being, Begin-date=desired-date, range-of-end-date, enddate=desired date),SUMIFS(Accomplishment points, range-of-acronyms,"SCE", range-of-being, Begin-date=desired-date, range-of-end-date, enddate=desired date), etc.)

}

我的Starup.cs

public void ConfigureServices(IServiceCollection services)         {             。 。

"dependencies": {
"EntityFramework.IBMDataServer": "7.0.0-beta1",
. . .

我的DBContext

        services.AddEntityFramework()
            .AddDb2()
            .AddDbContext<DB2.Models.Users.UserContext>();

        services.AddScoped<IUserRepository, UserRepository>();
    }

我的资料库

using Microsoft.Data.Entity;
using IBM.Data.Entity;

namespace DB2.Models.Users
{
    public class UserContext: DbContext
    {
        public DbSet<User> User { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseDb2(@"Server=x.x.x.x;Database=x;password=x;uid=x;");
            base.OnConfiguring(optionsBuilder);
        }        
    }
}  

执行此行时“var x = _context.User.First();”告诉我这个错误:

using System.Linq;

namespace DB2.Models.Users
{
    public class UserRepository: IUserRepository
    {
        private UserContext _context;

        public UserRepository(UserContext context)
        {
            _context = context;
        }

        public void pass()
        {
            var x = _context.User.First();            
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我看到你标记为db2400 - 这是IBM i还是iSeries?如果是这样,它有自己的DB2版本。如果上述情况属实,请使用IBM i Access for Windows附带的内容并添加对以下内容的引用:

C:\ Program Files(x86)\ IBM \ Client Access \ IBM.Data.DB2.iSeries.dll

您的安装可能位于不同的目录中。这将为您提供访问所需的内容。