_Samples/Example_Repository2_Entity.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;
using ComLib;
using ComLib.Application;
using ComLib.Data;
using ComLib.Account;
using ComLib.Entities;
using ComLib.Extensions;
namespace ComLib.Samples
{
/// <summary>
/// Example of Repository usage
/// NOTES:
/// 1. IRepository<T> is the interface where T : IEntity.
///
/// 2. RepositorySql(T) is a ms-sql database implementation of IRepository<T>
/// What makes the RepositorySql(T) generic is that T must be IEntity
/// and all the get / delete methods are based on the field "Id".
///
/// 3. The only thing you need to do to create your repository for eg. BlogRepository
/// is a. Extend from RepositorySql(T) and implement the Create() and Update() methods and RowMapper.
/// (If you use the codegenerator, this can be automated for you.)!.
///
/// 4. RepositoryInMemory(T) stores the objects in memory but still provides the CRUD methods.
/// This is useful for unit-tests / integration.
///
/// IEntity
/// 1. Id
/// 2. CreateDate
/// 3. UpdateDate
/// 4. CreateUser
/// 5. UpdateUser
///
/// This convention of using IEntity ( Id ) affords some very convenient pre-built funcionality.
/// Get, Delete, Recent, etc.
/// </summary>
public class Example_Repository2_Entity : App
{
/// <summary>
/// Run the application.
/// </summary>
public override BoolMessageItem Execute()
{
// Create In-Memory repository.
IRepository<Product> repo = new RepositoryInMemory<Product>("Id,Name,Model,IsInStock,Cost");
var products = GetSampleProducts();
products.ForEach( p => repo.Create(p));
// NOTE: I will not show the Sum, Min, Max, Distinct methods here, please refer to base class
// example Example_Repository1_Queryable.
后面还有 104 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
