massive
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
namespace ConsoleApplication1
{
class Program
{
// Https://github.com/robconery/massive
static void Main(string[] args)
{
//fun1();
//fun2();
//fun3();
//fun4();
//fun5();
//fun6();
//fun7();
}
private static void fun7()
{
dynamic table = new Product();
//var item = table.First(id: 1);
//int id = item.Id;
//var id = table.First(id:1).Id;
//var count = table.Count();
//var sum = table.Sum(columns:"id",id:3);
//var sum = table.Max(columns: "id");
}
private static void fun6()
{
var table = new Product();
var drinks = table.All();
foreach (var item in drinks.ToArray())
{
item.Specification = "hello";
}
table.Save(drinks.ToArray());
}
private static void fun5()
{
var table = new Product();
var newID = table.Insert(new { id = 11, Specification = "12345" });
}
private static void fun4()
{
var table = new Product();
var poopy = new { Specification = "123" };
table.Update(poopy, 3); // update set ="123" where id=3
}
private static void fun3()
{
//where id!=1 or id =2
var table = new Product();
var result = table.Query(@"select * from Product");
var result1 = table.Paged(where: " where id!=1 ",
currentPage: 2,
pageSize: 2);
}
private static void fun2()
{
dynamic table = new Product();
var productThree = table.Find(id: 3, columns: "Specification");
}
private static void fun1()
{
var table = new Product();
var query = table.All().ToList();
var productThree = table.All(columns: "Specification as sp",
where: "where id=@0",
args: 3);
}
}
public class Product : DynamicModel
{
public Product()
: base("TestProduct", "Product", "Id")
{
}
public override void Validate(dynamic item)
{
//required
ValidatesPresenceOf("id");
//ValidatesNumericalityOf("id");
if (item.id > 10)
Errors.Add("id must less than 10");
}
}
}