Entity Frameworkを使用せずに.Net CoreからSQL Serverに接続するにはどうすればよいですか?Entity Frameworkを使用せずに.Net CoreからSQL Serverに接続する方法は?
答えて
あなたは単に
public class BaseDataAccess
{
protected string ConnectionString { get; set; }
public BaseDataAccess()
{
}
{
public BaseDataAccess(string connectionString)
private SqlConnection GetConnection()
this.ConnectionString = connectionString;
}
{
if (connection.State != ConnectionState.Open)
SqlConnection connection = new SqlConnection(this.ConnectionString);
connection.Open();
return connection;
SqlCommand command = new SqlCommand(commandText, connection as SqlConnection);
}
protected DbCommand GetCommand(DbConnection connection, string commandText, CommandType commandType)
{
protected SqlParameter GetParameter(string parameter, object value)
command.CommandType = commandType;
return command;
}
{
parameterObject.Direction = ParameterDirection.Input;
SqlParameter parameterObject = new SqlParameter(parameter, value != null ? value : DBNull.Value);
return parameterObject;
}
SqlParameter parameterObject = new SqlParameter(parameter, type); ;
protected SqlParameter GetParameterOut(string parameter, SqlDbType type, object value = null, ParameterDirection parameterDirection = ParameterDirection.InputOutput)
{
if (type == SqlDbType.NVarChar || type == SqlDbType.VarChar || type == SqlDbType.NText || type == SqlDbType.Text)
{
}
parameterObject.Size = -1;
}
parameterObject.Direction = parameterDirection;
if (value != null)
{
parameterObject.Value = value;
}
else
{
parameterObject.Value = DBNull.Value;
}
return parameterObject;
DbCommand cmd = this.GetCommand(connection, procedureName, commandType);
protected int ExecuteNonQuery(string procedureName, List<DbParameter> parameters, CommandType commandType = CommandType.StoredProcedure)
{
int returnValue = -1;
try
{
using (SqlConnection connection = this.GetConnection())
{
if (parameters != null && parameters.Count > 0)
{
cmd.Parameters.AddRange(parameters.ToArray());
}
using (DbConnection connection = this.GetConnection())
returnValue = cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
//LogException("Failed to ExecuteNonQuery for " + procedureName, ex, parameters);
throw;
}
return returnValue;
}
protected object ExecuteScalar(string procedureName, List<SqlParameter> parameters)
{
object returnValue = null;
try
{
{
}
DbCommand cmd = this.GetCommand(connection, procedureName, CommandType.StoredProcedure);
if (parameters != null && parameters.Count > 0)
{
cmd.Parameters.AddRange(parameters.ToArray());
}
returnValue = cmd.ExecuteScalar();
}
}
catch (Exception ex)
{
//LogException("Failed to ExecuteScalar for " + procedureName, ex, parameters);
throw;
return returnValue;
}
ds = cmd.ExecuteReader(CommandBehavior.CloseConnection);
protected DbDataReader GetDataReader(string procedureName, List<DbParameter> parameters, CommandType commandType = CommandType.StoredProcedure)
{
DbDataReader ds;
try
{
DbConnection connection = this.GetConnection();
{
DbCommand cmd = this.GetCommand(connection, procedureName, commandType);
if (parameters != null && parameters.Count > 0)
{
cmd.Parameters.AddRange(parameters.ToArray());
}
}
}
catch (Exception ex)
{
}
//LogException("Failed to GetDataReader for " + procedureName, ex, parameters);
throw;
}
return ds;
}
詳細を見つけることができ、ここで
SqlConnection
は一例で使用して伝統的な方法を使用することができますhere
あなたがnugetを追加する必要が更新
パッケージ
Install-Package System.Data.SqlClient
that is still confusing for me... .Net Core & .Net standard vs regular .Net: How do we know which packages we can use with .Net core?
依存します は見てみましょう。ネットに依存関係がどのように機能するかをより深く理解するために何がパッケージまたはnugetを使用するためにあなたのマシンにインストールされているはずですが、それをインストールすることを意味しますhere
注 nugetパッケージ対象.net standard
ライブラリは、主に.NETのコアと.NETの標準フレームワークの両方で動作する場合に
で.Net Coreから標準の.Net Frameworkクラスを参照できますか?そのような種類の.Net Coreの敗北はありませんか? –
参照先のリンクは、Microsoft SQL Serverデータベースプロバイダ「Microsoft.EntityFrameworkCore.SqlServer」 –
を指し示しています。 –
- 1. .Net Core Consoleアプリケーション経由でEntity Framework Core 1.xからlocaldbに接続
- 2. Entity Framework 4を使用してSQL Serverに接続
- 3. Asp.netコアとEntity FrameworkがSQL Serverに接続できません
- 4. 接続からEntity Framework + PostgreSQLを使用するには?
- 5. Entity Frameworkを使用してSQL Server CE(.SDFファイル)に接続する
- 6. .NET Core Class Library(.NET Standard)を使用してSQL Serverデータベースに接続する方法?
- 7. ASP .Net Core - Entity Framework 7
- 8. Entity FrameworkでSQL Server Compactを使用するための接続文字列?
- 9. .Net CoreからMySQLに接続する方法
- 10. Entity Frameworkを使用したAspNet Core MVC +クラスライブラリ(.Net Standard)
- 11. Entity FrameworkでSQL Server Compact 3.5を使用する方法
- 12. SQL接続にSqlCredentialをEntity Frameworkと併用できますか?
- 13. .NETコード(Xamarin)からRealm Object Serverに接続する方法は?
- 14. Rを使用してSQL Serverに接続する方法は?
- 15. コンテキストを破棄せずにEntity Framework接続を更新するには
- 16. UWPでSQL ServerでEntity Frameworkを使用
- 17. ローカルPCからSQL Serverデータベースに接続する方法は?
- 18. モデルを使用せずにEntity Frameworkを使用して生のSQLクエリを実行する方法は?
- 19. C++/CLIを使用してSQL Serverに接続する方法
- 20. Entity Framework Core(コードファースト)を使用してSQLスクリプトを取得する方法
- 21. MonoDroidを使用してAndroidサーバーからSQL Serverに接続する方法
- 22. Entity FrameworkとSQL Serverデータベース接続文字列
- 23. Entity Framework:一見無作為なSQL Server接続エラー
- 24. ASP.NET Core 1 EF7でSQL Serverに接続できません
- 25. Entity Frameworkを使用したSql Azureへの接続「コードファースト」ctp 5
- 26. SQL Server CEに動的接続文字列を使用する方法は?
- 27. ASP.NET Core 1.0でEntity Framework 7を使用したSQL Serverビューの足場?
- 28. C#Entity Framework(.Net Core)検証(サーバー側)
- 29. PHP 7からMS SQL Server 2016に接続する方法
- 30. SQL ServerからAIXのIBM DB2データベースに接続する方法
これまでに試したこと –
@BRAHIMKamel私は.netコアを初めて使っています。これまでにすべての検索が始まりました** ** EF –