PostgreSQLへの接続クラスをを実装中なのですが、VB.NETに慣れていないため、
色々と調べても解決できず、苦戦しています。
元々、C# で Entity Frameworkへの接続クラスを実装、使用しており、そのまま
VB.NETに書き換えるだけのことなのですが、エラーになってしまいます。
実装したい内容は
C#版
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
using System;
using System.Data.Entity;
using Npgsql;
namespace NpgsqlAccess
{
class NpgsqlConnect : DbContext
{
#region 定数
private const string connString
= @"Server=localhost;Port=5432;User Id=postgres;Password=パスワード;Database=test;";
#endregion 定数
#region プロパティ
public DbSet<TTest> TTest { get; set; }
public string DefaultSchema { get; set; }
#endregion プロパティ
#region コンストラクタ
public NpgsqlConnect()
: base(new NpgsqlConnection(connString), true) // ←① VBではここでエラー
{
}
public NpgsqlConnect(bool bolP)
{
NpgsqlConnection conn;
string str = string.Empty;
using (conn = new NpgsqlConnection(connString))
{
try
{
conn.Open();
}
catch(Exception ex)
{
string error = ex.ToString();
}
}
}
#endregion コンストラクタ
//スキーマを変更する場合にはここに設定
// ↓② VBではここでエラー
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Configure default schema
modelBuilder.HasDefaultSchema("public");
}
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VB.NET版
エラー①
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#Region "コンストラクタ"
Public Sub New()
MyBase.New(NpgsqlConnection(connString), True)
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
エラーメッセージ
「'NpgsqlConnection' はクラス型であり、式として使用することはできません。」
エラー②
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
'Configure default schema
modelBuilder.HasDefaultSchema("public")
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
エラーメッセージ
「基底クラスで sub をオーバーライドしないため、sub 'OnModelCreating' を 'Overrides' として宣言することはできません。」
VB.NETの文法としての知識不足によるものだと思いますが、どなたかご教授いただけますようお願い申し上げます。