私はこのモデルのモデルを持っています:
public class Member
{
#region public property
public int Id { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public AccountState AccountState { get; set; }
public GodFatherType GodFatherType { get; set; }
}
AccountState と GodFatherType は両方とも 2 つの列挙体です。
public enum AccountState
{
NotActivated = 0,
Activated = 1,
Desactived = 2,
}
public enum GodFatherType
{
Undefined=0,
unknown = 1,
Correct = 2,
}
データベースには、Id、LastName、FistName、TinyInt
AccountstateId et smallint
GodFatherTypeid があります。ストアド プロシージャを変更したくありません。クラスMember
をデータベースにマップするにはどうすればよいですか??
実際には、次のコードでストアド プロシージャを実行すると、属性のみ Id、LastName、FistName のみを取得します。
public sealed class DbContext : IDbContext
{
private bool disposed;
private SqlConnection connection;
public DbContext(string connectionString)
{
connection = new SqlConnection(connectionString);
}
public IDbConnection Connection
{
get
{
if (disposed) throw new ObjectDisposedException(GetType().Name);
return connection;
}
}
public IDbTransaction CreateOpenedTransaction()
{
if (connection.State != ConnectionState.Open)
Connection.Open();
return Connection.BeginTransaction();
}
public IEnumerable<T> ExecuteProcedure<T>(string procedure, dynamic param = null, IDbTransaction transaction = null)
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
return Dapper.SqlMapper.Query<T>(connection, procedure, param, transaction,
commandType: CommandType.StoredProcedure);
}
public int ExecuteProcedure(string procedure, dynamic param = null, IDbTransaction transaction = null)
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
return Dapper.SqlMapper.Execute(connection, procedure, param, transaction,
commandType: CommandType.StoredProcedure);
}
public void Dispose()
{
Debug.WriteLine("** Disposing DbContext");
if (disposed) return;
if (connection != null)
{
connection.Dispose();
connection = null;
}
disposed = true;
}
}