在ASP.NET(不是核心)中,我通常会将一个machineKey添加到web.config中,这样我就可以在本地机器而不是服务器上执行某些功能,这样数据库/回调操作就会使用相同的键.例如
<system.web>
<machineKey validationKey="*********"
decryptionKey="*********"
validation="HMACSHA256"
decryption="AES" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何在ASP.NET Core 2.0中完成这项工作吗?
基本上我想要一个计算字段,当VeganOption = 1时递增1,当VeganOption = 0时递增为零
我尝试使用以下查询,但使用分区后继续增加零.我有点卡在这个上面.
SELECT [UniqueId]
,[Meal]
,[VDate]
,[VeganOption]
, row_number() over (partition by [VeganOption] order by [UniqueId])
FROM [Control]
order by [UniqueId]
Run Code Online (Sandbox Code Playgroud)
表数据:
CREATE TABLE Control
([UniqueId] int, [Meal] varchar(10), [VDate] datetime, [VeganOption] int);
INSERT INTO Control ([UniqueId], [Meal], [VDate], [VeganOption])
VALUES
('1', 'Breakfast',' 2018-08-01 00:00:00', 1),
('2', 'Lunch',' 2018-08-01 00:00:00', 1),
('3', 'Dinner',' 2018-08-01 00:00:00', 1),
('4', 'Breakfast',' 2018-08-02 00:00:00', 1),
('5', 'Lunch',' 2018-08-02 00:00:00', 0),
('6', 'Dinner',' 2018-08-02 00:00:00', 0),
('7', 'Breakfast',' 2018-08-03 00:00:00', …Run Code Online (Sandbox Code Playgroud) 我最初有代码处理DispatcherUnhandledException哪个会记录错误并将异常标记为已处理
protected override void OnStartup(StartupEventArgs e)
{
Dispatcher.UnhandledException += OnDispatcherUnhandledException;
}
...
void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
// Log Error here
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
我试图通过涵盖更广泛的未处理异常来改善这一点
protected override void OnStartup(StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += (s, ex) =>
LogUnhandledException((Exception)ex.ExceptionObject,
"AppDomain.CurrentDomain.UnhandledException");
DispatcherUnhandledException += (s, ex) =>
LogUnhandledException(ex.Exception,
"Application.Current.DispatcherUnhandledException");
TaskScheduler.UnobservedTaskException += (s, ex) =>
LogUnhandledException(ex.Exception,
"TaskScheduler.UnobservedTaskException");
}
Run Code Online (Sandbox Code Playgroud)
但我无法使用此事件处理异常
private void LogUnhandledException(Exception e, string @event)
{
// Log Error here
e.Handled = true; //Doesn't work
}
Run Code Online (Sandbox Code Playgroud)
我如何处理所有类型的异常,以便代码尝试继续?
如何将以下结果变为黄色?
我想找到上一年的最高分(不包括当前日期)和Name1和Parent1的分区
我已经尝试了以下没有给出所需结果的内容,它只返回正确分区的max,但是在所有日期之间.
select
[VDate]
,[Name1]
,[Parent1]
,[Score]
,max(case when [VDate] > dateadd(year, -1, [VDate]) then [Score] else null end) over (partition by [Name1], [Parent1]) AS MaxScoreInPreviousLast12Months
from [dbo].[Control]
Run Code Online (Sandbox Code Playgroud)
表数据:
CREATE TABLE Control
([VDate] datetime, [Name1] varchar(10), [Parent1] varchar(10), [Score] int);
INSERT INTO Control ([VDate], [Name1], [Parent1], [Score])
VALUES
('2018-08-01 00:00:00', 'Name1', 'Parent1', 80),
('2018-07-01 00:00:00', 'Name1', 'Parent1', 85),
('2018-06-01 00:00:00', 'Name1', 'Parent1', 90),
('2017-09-01 00:00:00', 'Name1', 'Parent1', 100),
('2017-08-01 00:00:00', 'Name1', 'Parent1', 95),
('2017-07-01 00:00:00', 'Name1', 'Parent1', 70),
('2018-08-01 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将ASPNET Core 2.0中的主键更改为Guid或long.
但是,在Startup类中,我收到以下错误
Error CS1061 'IdentityBuilder' does not contain a definition for
'AddEntityFrameworkStores' and no extension method 'AddEntityFrameworkStores' accepting
a first argument of type 'IdentityBuilder' could be found (are you missing a using
directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我认为原因是这些例子都是基于旧的ASPNET Core 1.0.如何在ASPNET Core 2.0中更改Identity的主键?
我正在dataGridView使用新的DataTable 更新a
dataGridView1.DataSource = table
Run Code Online (Sandbox Code Playgroud)
但是,当用户滚动dataGridView时,我不想这样做.如何检查滚动条是滚动还是滚动完成(即拖动而不是单击)?
我已经看过Scroll事件,但它似乎只是在第一次单击滚动条并且未完成时触发.谷歌搜索似乎也没有具体提到这一点.
通常在使用Linq时,我通常会使用Where或类似过滤掉空/空记录.但是,我需要在多个条件上订购一个列表,并按顺序保留列表中的所有项目.
以下内容仅.Dimension1.Count > 0适用于列表中的所有项目
var orderedList = mList.Elements
.OrderBy(x => x.Property1)
.ThenBy(x => x.Property2)
.ThenBy(x => x.Property3.Dimension1[0].Value2)
.ToList();
Run Code Online (Sandbox Code Playgroud)
如果有任何元素,Dimension1.Count == 0那么我得到错误:
'指数超出范围.必须是非负数且小于集合的大小.
这是预期的,因为数组没有标注尺寸.
当列表包含有哪些项目时,有没有办法使这项工作.Dimension1.Count = 0?
请注意,这Dimension1[0].Value2是double类型.
我有一个ASP.NET MVC视图,我使用LINQ将模型拆分为多个对象列表.
下面的代码的工作原理是我得到了正确的对象列表,var data但我无法将其转换为我的对象来访问属性.我收到错误
无法转换类型为'Grouping [<> f__AnonymousType3'2 [System.DateTime,System.String],MVCProj.Models.tblData2017]'的对象,以输入'MVCProj.Models.tblData2017
Index.cshtml查看:
@model IEnumerable<MVCProj.Models.tblData2017>
@{
ViewBag.Title = "Index";
}
<h2>Title</h2>
@{
var data = Model.Where(x => x.Start.Date == DateTime.UtcNow.Date)
.GroupBy(x => new { x.Start, x.Field2 }).ToList();
for (int i = 0; i < data.Count; i++)
{
var rowItem = (List<tblCards2017>)data[i]; //<-Error on this line
string header1 = $"{rowItem.Start.ToString("HH:mm")} {rowItem.Field2}";
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做以下任何一种情况
i)成功演员 var rowItem = (List<tblCards2017>)data[i];
要么
ii)使用linq获取正确的对象类型List<List<tblCards2017> data = Model.Where.....而不是当前类型var data = System.Collections.Generic.List<System.Linq.IGrouping<<>f__AnonymousType2<System.DateTime, string>, MVCProj.Models.tblData2017>>
c# ×6
linq ×2
sql ×2
sql-server ×2
t-sql ×2
asp.net-core ×1
asp.net-mvc ×1
datagridview ×1
winforms ×1
wpf ×1