linq

C# 获得另一个窗体句柄并发送消息(使用windows API)

爷,独闯天下 提交于 2021-01-14 07:58:13
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; namespace findWindowTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // Find Window // 查找窗体 // @para1: 窗体的类名 例如对话框类是"#32770" // @para2: 窗体的标题 例如打开记事本 标题是"无标题 - 记事本" 注意 - 号两侧的空格 // return: 窗体的句柄 [DllImport("User32.dll", EntryPoint = "FindWindow")] public static extern IntPtr FindWindow(string className, string windowName); /

Linq to Entities中的Datetime类型转换

雨燕双飞 提交于 2021-01-13 08:53:50
使用JavaScriptSerializer将Ado.net Entity Framework的实体转换为JSON。不过JavaScriptSerializer在序列化Datetime类型的处理有些特别: DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime dt=(DateTime)obj ; return string.Format(" new Date({0}) ", (long) ((dt.ToUniversalTime().Ticks - time.Ticks) / 0x2710L)) 生成的是类似"\/Date(1271729248060)\/"的字符串,而不是通常的时间格式。虽然这种做法有关于全球化和减少ajax传输量的考虑,但是在大多数的本地化应用中,我们其实只需要传递通常的时间格式字符串就行了。 虽然在Linq to Entities里不支持ToString()等类型转换,但是我们可以使用AsEnumerable()先将Linq to Entities的结果转换为IEnumerable,再使用ToString()方法把时间字段转化成String。 var list = ctx.UserInfo.Select(u => new { u.Id, u.Guid, u

Entity Framework Code First使用DbContext查询

≯℡__Kan透↙ 提交于 2021-01-10 12:39:48
  DbContext、DbSet及DbQuery是Entity Framework Code First引入的3个新的类,其中DbContext用于保持数据库会话连接,实体变化跟踪及保存,DbSet用于暂存实体类的变化跟踪,DbQuery用于提供查询跟你。    1、使用Set查询全部记录   使用DbContext查询首先需要保证DbContext的实例在使用完之后对资源的释放,释放DbContext实例资源的方法有两种:采用using代码块结构和调用DbContext实例的Dispose()方法。 using (var ctx = new PortalContext()) { foreach (var province in ctx.Provinces) { Console.WriteLine(province.ProvinceName); } } using (var ctx = new PortalContext()) { foreach (var province in ctx.Set<Province>()) { Console.WriteLine(province.ProvinceName); } }    2、使用LINQ排序、筛选等   1>、LINQ排序   LINQ表达式排序: using (var ctx = new PortalContext()) {

C#中利用LightningChart绘制曲线图表

你。 提交于 2021-01-09 09:40:18
最近在做一个“基于C#语言的电炉温控制软件设计”的设计,我在大学并不是专业学习C#语言编程的,对C#的学习研究完全是处于兴趣,所以编程技术也不是很厉害,遇到问题多参照网络上的开源码。 这不,在做这个课题的时候就遇到了这么一个问题,既然是要控制电炉温,就离不开温度曲线的实时绘制显示,就希望能够有那么一个控件能够完成曲线绘制,寻遍网络,尝试过许多控件,也试过VisualStudio2015中的Chart控件,效果都不是很好。有的网友说在Panel中直接DrawLine就行,我觉得更不行,CSDN中也有小伙伴提供使用pictureBox绘制的方法,但在我看来,还是不是十分理想。 在多次搜索下,终于找到了这么一个相当完美的控件:LightningChart 。 接下来就介绍一下,我用LightningChart绘制曲线的编程思路。 先给大家看一下最后的效果图吧,以便不是想要这种效果的小伙伴另寻他法: 这儿不得不提一下LightningChart的一个优点:在图中的曲线绘制区域滑动滚轮,还能随意地放大和缩小曲线便于观察曲线的细节,这儿附上向后滑动鼠标滚轮缩小曲线后的效果图: 用了LightningChart才发现它的强大,上图就是理想中我想要达到的效果。 这儿附上具体的绘制曲线的代码: using System; using System.Collections.Generic; using

Linq query that finds duplicates and removed them from a list [duplicate]

谁说胖子不能爱 提交于 2021-01-07 02:51:42
问题 This question already has answers here : LINQ compare two lists and remove (3 answers) Closed 7 hours ago . I'm trying to create a LINQ query that will look for duplicates in 2 lists and remove them from the first list. The code bellow will find the duplicate and return them, but I would like the query to return the unique items from notificationsFirst: using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) {

Linq query that finds duplicates and removed them from a list [duplicate]

守給你的承諾、 提交于 2021-01-07 02:51:13
问题 This question already has answers here : LINQ compare two lists and remove (3 answers) Closed 7 hours ago . I'm trying to create a LINQ query that will look for duplicates in 2 lists and remove them from the first list. The code bellow will find the duplicate and return them, but I would like the query to return the unique items from notificationsFirst: using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) {

C# 与 .NET Framework 对应关系

五迷三道 提交于 2021-01-05 21:57:25
C#各版本新增加功能(系列文章)   本系列文章主要整理并介绍 C# 各版本的新增功能。 C# 8.0 C#8.0 于 2019年4月 随 .NET Framework 4.8 与 Visual Studio 2019 一同发布,但是当前处于预览状态。预计在2019年9月正式发布。 目前提供以下功能可供试用: Readonly 成员 默认接口成员【 *重要,突破性的变革* 】请参考: C#8.0 中使用默认接口成员更新接口 模式匹配增强功能:Using 声明 Switch 表达式 属性模式 元组模式 位置模式 静态本地函数 可处置的 ref 结构 可为空引用类型 异步流【 *重要* 】 索引和范围 具体新增功能请查看 C#8.0 新增功能 C# 7.3 C#7.3 随 VS2017 v15.7 发布(2018年5月)。 自 Visual Studio 2017 版本 15.7 和 .NET Core 2.1 SDK 起,开始随附 C# 7.3。 具体新增功能请查看 C#7.3 新增功能 C# 7.2 C#7.2 随 VS2017 v15.5 发布(2017年11月)。自 Visual Studio 2017 版本 15.5 和 .NET Core 2.0 SDK 起,开始随附 C# 7.2。 具体新增功能请查看 C#7.2 新增功能 C# 7.1 C#7.1 随 VS2017

Output records which the values of the field are the same

十年热恋 提交于 2021-01-05 12:48:41
问题 This topic is may be dublicated. I asked in a different scenario under this topic and it is answered by Derviş Kayımbaşıoğlu. When I edited my topic like this and asked again, Derviş Kayımbaşıoğlu said I should ask this in a new topic. So I had to ask the question in a new topic. Here is data schema example: I have a list getting from the SQLite database like this: var decisions = _db.decisions.Where(x => x.CAT_ID == Cat.Id).ToList(); If the values of the REC_ID field in this list are the

Output records which the values of the field are the same

拈花ヽ惹草 提交于 2021-01-05 12:48:28
问题 This topic is may be dublicated. I asked in a different scenario under this topic and it is answered by Derviş Kayımbaşıoğlu. When I edited my topic like this and asked again, Derviş Kayımbaşıoğlu said I should ask this in a new topic. So I had to ask the question in a new topic. Here is data schema example: I have a list getting from the SQLite database like this: var decisions = _db.decisions.Where(x => x.CAT_ID == Cat.Id).ToList(); If the values of the REC_ID field in this list are the

Ignore global query filter for joined entities

微笑、不失礼 提交于 2021-01-05 07:10:09
问题 Global query filters are very handy when implementing tenant and soft deletion features. But my problem is is that when i write a query with joins, for instance dbContext .entity1 .Include("entity2.entity3.entity4") .Where(something) .select(something) .toList(); and every one of those entities has global filters, then in the generated SQL i get for every JOIN a full Subquery where it selects all fields of that entity and checks for the global filters. But i dont want that. I want the global