目录
- 71. item.label = $"{lstD[i].DeptName}({lstCamera.Count})";
- 72. 定义entity时不写传统的{get;set;}
- 73.
- 74. EF多对多
- 75. DateTime.Now.Subtract(x.GpsTime).TotalHours
- 76. queryModel.LogDate.Value.Year
- 77. .net导出Excel
- 78. User.Identity.Name
- 79.
- 80. EF忽略查询(待解决)
- 81. A_Model 映射到 B_Model
- 82.
- 83. list.Any()
- 82. dateTime.Psrse();
- 83.
- 83. model.LiangLength ?? 0
- 84. id = Guid.NewGuid()
- 85. DateTime.Subtract(DateTime t)
- 86. list.take(100)
- 87. DateTime.Value.Year
- 88. var 堆和栈
- 89. GroupBy 的用法
- 90. 将string字符串按,拆分并转成网络路径后存入list集合。
- 91. string.Join("-", z.Files)
- 92. ToModel() 方法
- 93. entity
- 94. LogHelper.LogInfo输出日志
- 95. lst.Select(Lambda)
- 96.
- 97. whereLambda表达式初始值,类似于SQL语句的“where 1=1”
- 98. string.IsNullOrEmpty()
- 99. lst.ForEach(Lambda)
- 100. dao.Table.Any(Lambda)
71. item.label = $“{lstD[i].DeptName}({lstCamera.Count})”;
item.label = $"{lstD[i].DeptName}({lstCamera.Count})";
输出结果如下:
“label”: “潜江市交通运输局(70)”,
72. 定义entity时不写传统的{get;set;}
public class IPCJobSModel
{public int Id { get; set; }/// <summary>/// 实际结束时间/// </summary>public DateTime? ActualEndTime { get; set; }public string IsOverdue{get{var TempIsOverdue = "NO";DateTime TempActualEndTime = ActualEndTime == null ? DateTime.Now : ActualEndTime.Value;if (TempActualEndTime> HandleEndTime){TempIsOverdue = "YES";}return TempIsOverdue;}}
}
73.

74. EF多对多
潜江-角色用户关联表
75. DateTime.Now.Subtract(x.GpsTime).TotalHours
List<PersonGps> lstOnPersonGps = lstPersonGps.Where(x => DateTime.Now.Subtract(x.GpsTime).TotalHours <= 0.5).ToList();
76. queryModel.LogDate.Value.Year
77. .net导出Excel
https://blog.csdn.net/zz743830597/article/details/104637050
78. User.Identity.Name
获取当前登录人的name
SysUserService userService = new SysUserService();
string userName = User.Identity.Name;
UserEntity userinfo = userService.GetUserByName(userName);
79.
IQueryable requredDataFields = data.Select(x => new { x.Title, x.NestedObject });
80. EF忽略查询(待解决)
利用EF查询数据库时,忽略查询某字段,提高查询效率;
81. A_Model 映射到 B_Model
/// <summary>/// 扩展工具类/// </summary>public static class Utils{// 运行时映射public static void ReflectCase<Oringin, Target>(Oringin origin, Target target){Type type = origin.GetType();Type type2 = target.GetType();PropertyInfo[] properties = type.GetProperties();for (int i = 0; i < properties.Length; i++){PropertyInfo propertyInfo = properties[i];bool flag = propertyInfo.Name == "Id";if (!flag){PropertyInfo[] properties2 = type2.GetProperties();for (int j = 0; j < properties2.Length; j++){PropertyInfo propertyInfo2 = properties2[j];bool flag2 = propertyInfo.Name == propertyInfo2.Name && propertyInfo.GetValue(origin) != null;if (flag2){propertyInfo2.SetValue(target, propertyInfo.GetValue(origin));}}}}}
82.
//public string DeleteTimeString//{// get { return DeleteTime == null ? "" : DeleteTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); }// set { DeleteTime = string.IsNullOrEmpty(value) ? DateTime.Now : DateTime.Parse(value); }//}
83. list.Any()
确定序列是否包含任何元素。
// 摘要:// 确定序列是否包含任何元素。//// 参数:// source:// 要检查是否为空的 System.Collections.Generic.IEnumerable`1。//// 类型参数:// TSource:// source 中的元素的类型。//// 返回结果:// 如果源序列包含任何元素,则为 true;否则为 false。//// 异常:// T:System.ArgumentNullException:// source 为 null。public static bool Any<TSource>(this IEnumerable<TSource> source);
82. dateTime.Psrse();
// 摘要:// 将日期和时间的字符串表示形式转换为其等效的 System.DateTime。//// 参数:// s:// 包含要转换的日期和时间的字符串。//// 返回结果:// 一个对象,它等效于 s 中包含的日期和时间。//// 异常:// T:System.ArgumentNullException:// s 为 null。//// T:System.FormatException:// s 中不包含有效的日期和时间的字符串表示形式。public static DateTime Parse(string s);
83.
public List<ChildrenModel> children { get; set; } = new List<ChildrenModel>();
83. model.LiangLength ?? 0
Dictionary<string, decimal> diclist = new Dictionary<string, decimal>();
diclist.Add("良", model.LiangLength ?? 0);
84. id = Guid.NewGuid()
id = Guid.NewGuid()
85. DateTime.Subtract(DateTime t)
从此实例中减去指定的日期和时间;
DateTime.Now.Subtract(x.GpsTime).TotalHours <= 0.5
86. list.take(100)
取lstOverload集合中的前100条进行遍历操作;更多和skip
foreach (OverloadCtrlEntity en in lstOverload.OrderByDescending(x => x.ArriveDate).Take(100))
{OverLoadModel model = new OverLoadModel();model.OverloadRate = en.OverloadRate;lst.Add(model);
}
87. DateTime.Value.Year
–>学会转换思维,当A.Year 行不通的时候(A 为 DateTime? 类型),可以试试 B.Year。
if (query.Year.HasValue)
{item = item.Where(x => x.RecordTime.Value.Year == query.Year);
}item = item.Where(x => x.RecordTime.Value.Month == query.Month);item = item.Where(x => x.RecordTime.Value.Day == query.Day);
88. var 堆和栈
参考:https://www.cnblogs.com/archor/archive/2011/10/26/3199375.html
89. GroupBy 的用法
List<string> userName = data.GroupBy(x => x.RecorderName).Select(x => x.Key).ToList();
90. 将string字符串按,拆分并转成网络路径后存入list集合。
string.Split(',').Select(k => Common.FilePathTrans(k, strDirName, strPublishAddr)).ToList());
91. string.Join(“-”, z.Files)
string.Join(",", z.Files) //用,将z.Files中的每个string字符串拼接形成一个字符串
92. ToModel() 方法
public static ShipPortRiskInfoModel ToModel(this ShipPortRiskInfoEntity entity){var m= entity.MapTo<ShipPortRiskInfoEntity, ShipPortRiskInfoModel>();if (entity.IPCJobId.HasValue)m.IsJob = true;elsem.IsJob = false;return m;}
public static CaseInfoModel ToModel(this CaseInfoEntity entity){var m = entity.MapTo<CaseInfoEntity, CaseInfoModel>();var result= m.ExcuteUserIds.Split(',').ToList();SysUserService userService = new SysUserService();var names = new List<string>();result.ForEach(x =>{var user = userService.GetEntity(x.ToInt().Value);if(user != null)x = user.RealName;names.Add(x);});m.ExcuteUserName = string.Join(",", names) ;if (entity.IPCJobId.HasValue)m.IsJob = true;elsem.IsJob = false;return m;}
93. entity
public class IndexEvaConfigEntity{public IndexEvaConfigEntity(){AssessName = string.Empty;Grade = string.Empty;}public int Id { get; set; }public string AssessName { get; set; }public string Grade { get; set; }[DecimalPrecision(12, 3)]public decimal MinValue { get; set; }[DecimalPrecision(12, 3)]public decimal MaxValue { get; set; }public string Color { get; set; }public int? Width { get; set; }}
94. LogHelper.LogInfo输出日志
string funcName = MethodBase.GetCurrentMethod().Name;LogHelper.LogInfo(JsonConvert.SerializeObject(grid), funcName);LogHelper.LogInfo(JsonConvert.SerializeObject(model), funcName);LogHelper.Debug(funcName + JsonConvert.SerializeObject(req));
95. lst.Select(Lambda)
var query = routeReposity.Table.Select(x => new {DeleteState = x.DeleteState,RouteCode = x.RouteCode,RouteCharacter = x.RouteCharacter,Id = x.Id,RouteName = x.RouteName,TechLevel = x.TechLevel,RouteLength = x.RouteLength,SourceData = x.SourceData});
96.
protected override IEnumerable<FileSystemConfigurationEntry> ProcessEntries(ICollection<FileSystemConfigurationEntry> entries){entries.ForEach(e =>{Logger.Debug("Processing publisher configuration entry: {0}...", e.FileInfo.Name);var configType = Type.GetType(e.Entry.ConfigurationType);var config = Serialiser.FromJson(e.Entry.Data, configType);if (IsDisabled(config))return;var name = Path.GetFileNameWithoutExtension(e.FileInfo.Name);Container.RegisterInstance(configType, config, name);FindAndExecuteBootstrappers(configType, config);e.Entry.RequiredProperties.AddIfMissing(Tuple.Create(ConfigurationEntry.RequiredPropertyNames.NAME, name));if (string.IsNullOrWhiteSpace(e.Entry.PluginType))return;var pluginType = Type.GetType(e.Entry.PluginType);var pluginName = string.Format("{0}.{1}", pluginType.AssemblyQualifiedName, name);Container.RegisterAsSingletonWithInterception<INotificationEventPublisher, IPublisherFilter>(pluginType,pluginName,new Tuple<Type, string>(configType, name));});return entries;}
97. whereLambda表达式初始值,类似于SQL语句的“where 1=1”
Expression<Func<UserEntity, bool>> whereLambda = x => x.Id > 0; //whereLambda表达式初始值,类似于SQL语句的“where 1=1”
98. string.IsNullOrEmpty()
if (!string.IsNullOrEmpty(queryModel.BtnName)){query = query.Where(x => x.BtnName.Contains(queryModel.BtnName));}
99. lst.ForEach(Lambda)
model.ForEach(x =>{sql = string.Format(@" -- 桥梁汇总select 0, convert(varchar(64), NEWID()) IsUnique , '桥梁' Label, count(1) Number ,'qiaoliangguanli' ParentIcon,'#F89017' IconColor from BMS_D_Bridge left join BMS_S_AssetType B on B.TypeName='桥梁' {0}union -- 隧道汇总select 1, convert(varchar(64), NEWID()) IsUnique, '隧道' Label, count(1) Number ,'suidaoguanli' ParentIcon,'#00A854'IconColor from BMS_D_Tunnel left join BMS_S_AssetType B on B.TypeName='隧道' {0}union-- 涵洞汇总 --暂时无此表select 2,convert(varchar(64), NEWID()) IsUnique, '涵洞' Label, count(1) Number ,'handongguanli' ParentIcon, '##00A854'IconColor from BMS_D_Tunnelunion-- 大类汇总select 3,convert(varchar(64), NEWID()) IsUnique, A.TypeName Label, null as Number,A.Icon ParentIcon,IconColor from BMS_S_AssetMainType A where A.TypeName not like '%桥%' and A.TypeName not like '%隧%' and A.TypeName not like '%涵%' and SortCode>0", Important == 0 ? "" : "where B.IsCommonType=1");if (sql != string.Empty){x.children = dao.FindList<AssetChildrenModel>(sql);}// x.children = x.children.Where(xx => xx.Number != null && xx.Number > 0).ToList();sql = string.Empty;x.children.ForEach(y =>{switch (y.Label){case "桥梁":sql = string.Format(@" select 'qiaoliangguanli' ParentIcon,'#00a953' IconColor, '一类' Label ,convert(varchar(64), NEWID()) IsUnique union select 'qiaoliangguanli' ParentIcon,'#1a8fff' IconColor, '二类' Label ,convert(varchar(64), NEWID()) IsUnique union select 'qiaoliangguanli' ParentIcon,'#ffc001' IconColor, '三类' Label ,convert(varchar(64), NEWID()) IsUnique union select 'qiaoliangguanli' ParentIcon,'#fa9e47' IconColor, '四类' Label ,convert(varchar(64), NEWID()) IsUnique union select 'qiaoliangguanli' ParentIcon,'#f04033' IconColor, '五类' Label ,convert(varchar(64), NEWID()) IsUnique ");//sql = string.Format(@" select convert(varchar(64), NEWID()) IsUnique,'桥梁' AssetType, A.Id AssetId, BridgeName Label,NULL Number,CenterLon Lon,CenterLat Lat, 'dingwei3' LeafIcon, 'qiaoliangguanli' ParentIcon , B.Id LayerId ,'#F89017' IconColor ,// (case when a.BridgeLevel in ('四类','五类') then 1 else 0 end) as State, (case when a.BridgeLevel in ('四类','五类') then 'shexiangtou' else '' end) as LeafIcon1 from BMS_D_Bridge A left join YC_S_MapLayer B// on B.LayerName='桥梁' left join BMS_S_AssetType C on C.TypeName='桥梁' {0}", Important == 0 ? "" : "where C.IsCommonType = 1");break;case "隧道":sql = string.Format(@" select convert(varchar(64), NEWID()) IsUnique,'隧道' AssetType, A.Id AssetId ,TunnelName Label,NULL Number,ULon Lon,ULat Lat, 'dingwei3' LeafIcon, 'suidaoguanli' ParentIcon , B.Id LayerId ,'#00A854' IconColor from BMS_D_Tunnel A left join YC_S_MapLayer Bon B.LayerName='隧道' left join BMS_S_AssetType C on C.TypeName='隧道' {0}", Important == 0 ? "" : "where C.IsCommonType = 1");break;case "涵洞":sql = string.Format(@" select convert(varchar(64), NEWID()) IsUnique ,'涵洞' AssetType,0 AssetId, '涵洞' Label,NULL Number,null Lon,null Lat, 'dingwei3' LeafIcon, 'handongguanli' ParentIcon ,'#F89017' IconColor ");break;default:sql = string.Format(@" select convert(varchar(64), NEWID()) IsUnique ,B.TypeName AssetType, B.TypeName Label,'' LeafIcon, B.Icon ParentIcon, count(1) Number, D.Id LayerId , B.IconColor from BMS_S_AssetMainType A join BMS_S_AssetType B on A.Id=B.MainTypeId join BMS_D_AssetData C on A.id=C.MainTypeId and B.Id=C.TypeIdleft join YC_S_MapLayer D ON B.TypeName=D.LayerName where C.deleteState=0 and A.TypeName='{0}' {1} group by A.TypeName, B.Id ,B.TypeName,B.Icon,D.Id , B.IconColor", y.Label, Important == 0 ? "" : "and B.IsCommonType = 1");break;}if (sql != string.Empty){if (y.Label == "桥梁"){y.children = dao.FindList<ChildrenModel>(sql);// 自定义排序string[] BridgeLevelSort = new string[] { "一类", "二类", "三类", "四类", "五类" };y.children = y.children.OrderBy(e =>{var index = Array.IndexOf(BridgeLevelSort, e.Label);if (index != -1) return index;else return int.MaxValue;}).ToList();}else{y.children = dao.FindList<ChildrenModel>(sql);}}// y.children = y.children.Where(yy => yy.Number > 0).ToList();sql = string.Empty;y.children.ForEach(o =>{sql = string.Format(@" select convert(varchar(64), NEWID()) IsUnique,'桥梁' AssetType, A.Id AssetId, BridgeName Label,NULL Number,CenterLon Lon,CenterLat Lat, 'dingwei3' LeafIcon, 'qiaoliangguanli' ParentIcon , B.Id LayerId ,'{2}' IconColor ,(case when d.CameraSerial is not null then 1 else 0 end) as State, (case when d.CameraSerial is not null then 'shexiangtou' else '' end) as LeafIcon1,(case when d.CameraSerial is not null then 'shexiangtou' else '' end) as strToken from BMS_D_Bridge A left join YC_S_MapLayer Bon B.LayerName='桥梁' left join BMS_S_AssetType C on C.TypeName='桥梁' left join BMS_D_AssetCameraInfo d on a.Id=d.AssetId where a.BridgeLevel='{0}' {1}", o.Label, Important == 0 ? "" : "and C.IsCommonType = 1", o.IconColor);if (sql != string.Empty){o.children = dao.FindList<ChildrenModel>(sql);}o.children.ForEach(z =>{sql = string.Format(@" select A.Id AssetId, CenterLon Lon,CenterLat Lat,(case when d.CameraSerial is not null then 1 else 0 end) as State,(case when d.CameraSerial is not null then 'shexiangtou' else '' end) as LeafIcon1,(case when d.CameraSerial is not null then 'shexiangtou' else '' end) as strToken from BMS_D_Bridge A left join BMS_S_AssetType C on C.TypeName = '桥梁' left join BMS_D_AssetCameraInfo d on a.Id=d.AssetId {1} where A.Id={0} ", z.AssetId, Important == 0 ? "" : "where C.IsCommonType = 1");if (sql != string.Empty){z.Palce = dao.FindList<PlaceModel>(sql);z.Palce = z.Palce.Where(zz => zz.Lat.ToString().IndexOf(".") >= 0).ToList();}});});
100. dao.Table.Any(Lambda)
dao.Table.Any(x => x.SourceId == entity.SourceId && x.SourceData == entity.SourceData)















