EF6-UnitOfWork 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EF6-UnitOfWork --version 0.2.0
NuGet\Install-Package EF6-UnitOfWork -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EF6-UnitOfWork" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EF6-UnitOfWork --version 0.2.0
#r "nuget: EF6-UnitOfWork, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EF6-UnitOfWork as a Cake Addin
#addin nuget:?package=EF6-UnitOfWork&version=0.2.0

// Install EF6-UnitOfWork as a Cake Tool
#tool nuget:?package=EF6-UnitOfWork&version=0.2.0

Repository

用來處理資料庫內某 model 的資料查詢、更新、新增、刪除。

  • IQueryRepository<TEntity>:用於唯讀的查詢,可直接從 IUnitOfWorkQueryRepository<TEntity>() 的方法中取得某 model 的 IQueryRepository 物件。

/* IQueryRepository<TEntity> 介面 */

public interface IQueryRepository<TEntity> : IDisposable where TEntity : class
{
	/// <summary>
	/// 取得某一筆資料
	/// </summary>
	/// <param name="predicate">The predicate.</param>
	/// <returns></returns>
	TEntity Get(Expression<Func<TEntity, bool>> predicate);

	/// <summary>
	/// 取得全部資料來做查詢
	/// </summary>
	/// <returns></returns>
	IQueryable<TEntity> GetAll();
}

  • IRepository<TEntity>:除了查詢外,可以做到 model 的更新、新增及刪除,必須自定義處理 model 的類別以供其他程式呼叫。

/* IRepository<TEntity> 介面 */
public interface IRepository<TEntity> : IQueryRepository<TEntity> where TEntity : class
{
	TEntity Create(TEntity instance);

	/// <summary>
	/// 依照  PrimaryKey 更新欄位
	/// </summary>
	/// <typeparam name="TProperty">The type of the property.</typeparam>
	/// <param name="keyValues">The key values.</param>
	/// <param name="property">The property.</param>
	/// <param name="value">The value.</param>
	void Update<TProperty>(object[] keyValues, Expression<Func<TEntity, TProperty>> property, TProperty value);

	/// <summary>
	/// 依MODEL的值更新
	/// </summary>
	/// <param name="instance">The instance.</param>
	/// <param name="keyValues"></param>
	void Update(TEntity instance, params object[] keyValues);


	/// <summary>
	/// Deletes the specified instance.
	/// </summary>
	/// <param name="instance">The instance.</param>
	/// <param name="keyValues">The key values.</param>
	/// <returns></returns>
	void Delete(TEntity instance, params object[] keyValues);
}

  • GenericRepository<TEntity>:此類別實作 IRepository<TEntity> 的基本增改刪功能,供其他自定 Repository 繼承。

如想要變更 Budget 這個 model,需宣告 IBudgetRepository 這個介面,並繼承 IRepository<Budget>。及宣告 BudgetRepository 並繼承GenericRepository<Budget>,並實作。


public interface IBudgetRepository : IRepository<Budget>
{

}

public class BudgetRepository : GenericRepository<Budget>, IBudgetRepository
{
	public BudgetRepository(IToolMngFactory factory) : base(factory)
	{
	}
}

UnitOfWork

UnitOfWork 內為處理 DB 資料的實體及其 factory

  • IUnitOfWork:用來處理取得 Repository 或 QueryRepository、Save Changes、Begin Transaction 行為。
  • IUnitOfWorkFactory:用來產生 IUnitOfWork 實體的工廠介面。
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.4.0 1,086 6/1/2018
0.2.0 940 6/1/2018

UnitOfWork pattern by EF6