linq

基于Dapper的开源LINQ扩展,且支持分库分表自动生成实体二

痴心易碎 提交于 2021-01-25 03:23:05
LnskyDB LnskyDB是基于Dapper的Lambda扩展,支持按时间分库分表,也可以自定义分库分表方法.而且可以T4生成实体类免去手写实体类的烦恼. 文档地址: https://liningit.github.io/LnskyDB/ 开源地址: https://github.com/liningit/LnskyDB nuget地址: https://www.nuget.org/packages/LnskyDB/ 功能特点 Lambda表达式查询方便 基于Dapper的Lambda表达式扩展可以方便的进行查询筛选操作 支持分库分表 默认支持按年分库按月分表,也支持自定义分库分表.从此大数据不用愁 T4自动生成实体 有T4模板自动生成实体类,再也不用手写那些烦人的实体类了.仓储类及接口也支持自动生成 使用门槛低,快速上手 使用非常简单,可以快速上手 注意问题 本框架只支持单表的Lambda表达式查询,如果多表需要手写sql,框架支持根据sql查询修改等. 另外不太建议连表查询,推荐在逻辑层处理 开源协议 MIT license. 上一期我们写了分库分表的增删改查,这一期我们写一下不分库分表的增删改查: 不分库分表 查询 根据主键查询 var repository = RepositoryFactory.Create<ProductSaleByDayNSEntity>();

WPF 触摸屏小键盘样式

久未见 提交于 2021-01-25 03:13:28
WPF程序,用于平板时,一些输入数量的地方我们需要弹出小键盘输入,这个键盘可以调系统的,也可以自己写。 分享个我现在用的一个数字键盘界面。 < Window xmlns:dxe ="http://schemas.devexpress.com/winfx/2008/xaml/editors" x:Class ="NFMES.UI.Base.NumericKeyBoard" xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml" WindowStyle ="None" Background ="#FF333333" Title ="NumericKeyBoard" ResizeMode ="NoResize" Height ="400" Width ="300" Deactivated ="Window_Deactivated" FocusManager.FocusedElement =" {Binding ElementName=btn} " > < Window.Resources > < Style TargetType =" {x:Type Button} " > < Setter

dotnet Core 异步任务

血红的双手。 提交于 2021-01-24 13:37:44
使用线程池中线程的任务启动方式 线程池提供了一个后台线程的池,独自管理线程,按需增加或减少线程池中的线程数。线程池中的线程用于执行一些动作后仍然返回线程池中。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.IO; namespace TaskSamples { class Program { static void Main() { TasksUsingThreadPool(); Console.ReadLine(); } static void TasksUsingThreadPool() { var tf = new TaskFactory(); Task t1 = tf.StartNew(TaskMethod, "using a task factory"); Task t2 = Task.Factory.StartNew(TaskMethod, "factory via a task"); var t3 = new Task(TaskMethod, "using a task constructor and Start

How to check list A contains any value from list B?

限于喜欢 提交于 2021-01-20 14:16:25
问题 List A: 1, 2, 3, 4 List B: 2, 5 How to check if list A contains any value from list B? e.g. something like A.contains(a=>a.id = B.id)? 回答1: If you didn't care about performance, you could try: a.Any(item => b.Contains(item)) // or, as in the column using a method group a.Any(b.Contains) But I would try this first: a.Intersect(b).Any() 回答2: I've profiled Justins two solutions. a.Any(a => b.Contains(a)) is fastest . using System; using System.Collections.Generic; using System.Linq; namespace

How to check list A contains any value from list B?

柔情痞子 提交于 2021-01-20 14:16:09
问题 List A: 1, 2, 3, 4 List B: 2, 5 How to check if list A contains any value from list B? e.g. something like A.contains(a=>a.id = B.id)? 回答1: If you didn't care about performance, you could try: a.Any(item => b.Contains(item)) // or, as in the column using a method group a.Any(b.Contains) But I would try this first: a.Intersect(b).Any() 回答2: I've profiled Justins two solutions. a.Any(a => b.Contains(a)) is fastest . using System; using System.Collections.Generic; using System.Linq; namespace

Linq to group by two fields and average

倖福魔咒の 提交于 2021-01-20 13:07:07
问题 I have the following C# models: public class RawData { public int questionnaireId { get; set; } public int coachNodeId { get; set; } public int questionnaireNumber { get; set; } public float score { get; set; } } public class AveragedData { public int coachNodeId { get; set; } public int questionnaireNumber { get; set; } public float averageScore { get; set; } } I have an API endpoint which is returning data from a database, mapped as List<RawData> . The values are like this: questionnaireId

Linq to group by two fields and average

邮差的信 提交于 2021-01-20 13:04:39
问题 I have the following C# models: public class RawData { public int questionnaireId { get; set; } public int coachNodeId { get; set; } public int questionnaireNumber { get; set; } public float score { get; set; } } public class AveragedData { public int coachNodeId { get; set; } public int questionnaireNumber { get; set; } public float averageScore { get; set; } } I have an API endpoint which is returning data from a database, mapped as List<RawData> . The values are like this: questionnaireId

C#Linq之求和,平均值,最大值,最小值

南笙酒味 提交于 2021-01-19 04:36:25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Wolfy.LinqAggregation { class Program { static void Main(string[] args) { //生成测试数据 List<Product> list = new List<Product>(); Random r = new Random(); for (int i = 0; i < 5; i++) { float iran = r.Next(1, 111); Product pro = new Product() { ID = i + 1, Name = "宝马" + i.ToString(), Price = iran * 1000, ProductDate = DateTime.Now.AddDays(i) }; Product pro2 = new Product() { ID = i + 1, Name = "宝马" + i.ToString(), Price = iran * 1000, ProductDate = DateTime.Now.AddDays(i) };

C#定时任务之FluentScheduler

Deadly 提交于 2021-01-18 18:59:27
一、业务需求 平台首页,有几个指标统计,产品不要求实时性,觉得一天更新一次可以接受。 最后决定用FluentScheduler定时执行统计,redis缓存结果。 每天晚上1点进行定时任务统计,将统计结果缓存到redis中,业务接口直接从reids里拿统计数据。 二、开始撸代码 方式一:多个任务 + 不同时间段执行(这个没有实现,大家可以使用 一个从0点开始的分钟数,秒数等,自定义一个接口,根据规则去调用Schedule中的方法) using System; using System.Linq; using System.Threading.Tasks; using FluentScheduler; namespace Common { // 自己定义了一个接口,目前只有一个方法,大家可以根据自己的需求添加接口,比如定义一个执行任务的时间接口等 public interface IScheduleTask { void Execute(); } public class ScheduleTask : Registry { public ScheduleTask() { // 获取已加载到此应用程序域的执行上下文中的程序集(因为有延迟加载机制, // 未加载到应用程序域的时候会报错,一般初始化的时候可能会再现问题) // var types = AppDomain

C#Linq to XML的简单读写

夙愿已清 提交于 2021-01-18 10:48:11
Linq to XML Linq是C#3.0中出现的一个新特性,可以很方便操作XML文件 写入数据 需要引入using System.Xml.Linq;命名空间 string dirPath = "xmlData.xml" ; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance" ; XNamespace xsd = "http://www.w3.org/2001/XMLSchema" ; string Code1 = "A" ; //属性1 string Code2 = "B" ; //属性2 string Code3 = "C" ; //属性3 XDocument doc = new XDocument ( new XDeclaration ( "1.0" , "UTF-8" , null ) , //(版本,编码,独立属性) new XElement ( "ROOT" , //添加根节点 new XAttribute ( XNamespace . Xmlns + "xsi" , xsi ) , //添加命名空间 new XAttribute ( XNamespace . Xmlns + "xsd" , xsd ) , //添加命名空间 new XAttribute ( "Code1" , Code1 ) ,