_Samples/Example_Repository1_Querable.cs
(开头部分) 6KB这里只显示每个文件的开头 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 IRepositoryQuerable - generic functionality on any table.
/// The repository is not associated w/ any specific entity.
/// </summary>
public class Example_Repository1_Querable : App
{
/// <summary>
/// Run the application.
/// </summary>
public override BoolMessageItem Execute()
{
// First create some test data for the queries.
IRepository<Product> repoCrud = new RepositoryInMemory<Product>();
var products = GetSampleProducts();
products.ForEach( p => repoCrud.Create(p));
// NOTES:
// 1. The Repository<T>'s base class is RepositoryQueryable.
// 2. We are only using a IRepository<T> here initially for adding in-memory test data.
// 3. But this could be initialized via new RepositoryQuerable(...) constructors against a real Database.
// 4. Notice that IRepositoryQueryable does not know anything about the entity(Product).
IRepositoryQueryable repo = (IRepositoryQueryable)repoCrud;
// 0. Named filters first, to show their example in each section min, max, group, etc.
repo.AddNamedFilter("InStock Filter", Query<object>.New().Where("IsInStock").Is(true));
repo.AddNamedFilter("Expensive", Query<object>.New().Where("Cost").MoreThan(20));
// 1. GROUPING
var groups = repo.Group<int>("Cost");
var groups2 = repo.Group<int>("Cost", Query<object>.New().Where("Make").Not("Honda"));
var groups3 = repo.Group<int>("Cost", "Expensive"); // same as groups2.
// 2. DISTINCT
var names = repo.Distinct<string>("Make");
var names2 = repo.Distinct<string>("Make", Query<object>.New().Where("Cost").MoreThan(30).OrderByDescending("Make"));
var names3 = repo.Distinct<string>("Make", "Expensive");
// 3. COUNT
var count1 = repo.Count();
var count2 = repo.Count(Query<object>.New().Where("IsInStock").Is(true));
后面还有 94 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
