_Samples/Example_Repository3_Versioned.cs
(开头部分) 2KB这里只显示每个文件的开头 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 an Repository that versions the entities it stores.
/// This is a decorated that can be used with any underlying repository
/// </summary>
public class Example_Repository3_Versioned : App
{
/// <summary>
/// Run the application.
/// </summary>
public override BoolMessageItem Execute()
{
// Create In-Memory repository.
IRepository<Product> underlyingRepo = new RepositoryInMemory<Product>(true, "Id,Name,Cost,Version,VersionRefId");
// NOTES:
// 1. Now create the versionable repo, via decoration.
// 2. Need to use flag : useOptimizedQueries = false, to enable use of In-Memory Repository.
// 3. The Entity T must implement the IEntityVersionable interface, see entity below.
IRepositoryVersionable<Product> repo = new RepositoryVersioned<Product>(underlyingRepo, true, false);
((int)4).Times(ndx =>
{
// Create more than 1 item w/ same cost, this is for group by functionality.
int cost = ndx % 2 == 0 ? 10 : 20;
var newProduct = new Product("Product" + ndx, cost);
repo.Create(newProduct);
});
// 1. Just get the id of the first entity for testing.
int id = repo.GetAll()[0].Id;
// 2. Update it 2 times to create 3 versions
// v1 = original, v2 = update 1, v3 = update 2
var product = repo.Get(id);
product.Name = product.Name + " update 1";
repo.Update(product);
product = repo.Get(id);
product.Name = product.Name + " update 2";
repo.Update(product);
后面还有 33 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
