我试图找出插入多个记录(超过200)的最佳方法,如果它们不存在,而不是为每个记录检查它是否存在,我喜欢这样:
foreach (var node in nodes)
{
if (!context.Nodes.Any(x => x.Name == node.Name))
{
context.Nodes.Add(new NWatchNode(node));
}
try
{
if (context.Nodes.Local.Any())
{
context.SaveChanges();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
做这个的最好方式是什么?
如何模拟该CasOperations.GetImpairedNodesFromCASpectrumAsync()方法以使其返回模拟值?目前,我遇到了异常(如代码示例所示)。
我有以下设置:
要模拟的类和属性:
public class BranchCircuitStatusScheduleEntry : NWatchCustomScheduleEntryBase, INWatchCustomScheduleEntry
{
public BranchCircuitStatusScheduleEntry(INWatchSchedulerApplication application)
: base(application, DevOpsScheduleFrequency.Minute, 15, 0, DevOpsScheduleFlags.Always)
{
// Some initialization for below properties
CasOperations = new CasOperations(cas, EntityService, IsBranchesOnly);
}
public CasOperations CasOperations { get; private set; }
}
public class CasOperations
{
public CasOperations(CasApi casApi, BranchCircuitEntityService entityService, bool isBranchesOnly)
{
CAS = casApi;
this.entityService = entityService;
this.isBranchesOnly = isBranchesOnly;
}
}
Run Code Online (Sandbox Code Playgroud)
尝试执行模拟的测试:
[TestMethod]
public void DownNodeRediscoveredInSpectrum()
{
var mock = new Mock<BranchCircuitStatusScheduleEntry>(_application);
mock.CallBase = …Run Code Online (Sandbox Code Playgroud) 我的路由配置方式如下:
RouterModule.forRoot([
{ path: '', redirectTo: 'main', pathMatch: 'full' },
{ path: 'main', component: SummaryComponent, children: [
{ path: 'data/:deviceId/:incidentId', component: DeviceMetricsComponent },
{ path: 'incident/analysis/:incidentId', component: IncidentAnalysisComponent },
]
},
{ path: 'test', component: TestFullPageComponent, children: [
{ path: 'test2', component: TestFullPageChildComponent}
]
},
{ path: 'logs/jobs/:jobtype', component: JobLogsComponent, pathMatch: 'full' },
{ path: '**', redirectTo: 'main' }
])
Run Code Online (Sandbox Code Playgroud)
这是我的"主要"模板:
<div class="row">
<div class="col-md-12">
<!-- Some links are in this table that load into the router-outlet below -->
<app-incident-node-table …Run Code Online (Sandbox Code Playgroud) 我有以下查询,其中节点是MonProfiles内的导航属性.
var nodes = await dbContext.MonProfiles.Include(x => x.Nodes).
Where(x => x.Id == profileId).
Select(x => x.Nodes.
Select(y => new { y.NodeNativeId, y.NodeClassId, y.NodeName, y.NodeClass.ClassName })).
ToListAsync();
return Json(new { nodes });
Run Code Online (Sandbox Code Playgroud)
我面临的问题是在数组中的数组中返回的JSON:
{
"nodes": [[{
"NodeNativeId": 1234567,
"NodeClassId": 9999,
"NodeName": "TestName",
"ClassName": "TestClassName"
}]]
}
Run Code Online (Sandbox Code Playgroud)
我想回来的是:
{
"nodes": [{
"NodeNativeId": 1234567,
"NodeClassId": 9999,
"NodeName": "TestName",
"ClassName": "TestClassName"
}]
}
Run Code Online (Sandbox Code Playgroud)
这是我第一次使用LINQ来选择属于Navagation属性的各个属性,这是我第一次遇到这种类型的结果.如何更正我的LINQ查询,以便获得我期望的JSON输出?
我对此有点困惑,因为我已经读过一个int []数组,虽然int是一个基本类型,因为它是一个数组,它是一个引用类型变量.
那么方法之间有什么不同,例如:
public static void ChangeSomething(ref int[] array)
{
array[0] = 100;
}
Run Code Online (Sandbox Code Playgroud)
和
public static void ChangeSomething(int[] array)
{
array[0] = 100;
}
Run Code Online (Sandbox Code Playgroud)
修改数组后,我可以在索引0处看到这两个调用的新值100.
是否有不同的事情发生在封面下,使一个人比另一个更好?VS IDE是否允许这两者只是因为"ref"关键字可能澄清了意图?
我想知道如何使用居中的微调器获得覆盖整个页面的长度/宽度。
我在网上找到了以下微调器,看起来不错,但它们的叠加仅占页面的 25% 左右。我是一名后端开发人员,并不擅长 CSS。我需要进行哪些调整才能使叠加层达到 100%,并z-index增加到后面的元素不可点击?
.spinner {
margin: 100px auto;
width: 50px;
height: 40px;
text-align: center;
font-size: 10px;
}
.spinner>div {
z-index: 999;
background-color: black;
height: 100%;
width: 6px;
display: inline-block;
-webkit-animation: sk-stretchdelay 1.2s infinite ease-in-out;
animation: sk-stretchdelay 1.2s infinite ease-in-out;
}
.spinner .rect2 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.spinner .rect3 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.spinner .rect4 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.spinner .rect5 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
@-webkit-keyframes sk-stretchdelay { …Run Code Online (Sandbox Code Playgroud)我将.content-container div设置为display: flex,并将子div(.message-body, .message-action)并排显示,并且.message-actiondiv浮动在右侧。
这是我正在做的事情:https : //codepen.io/anon/pen/ZRZKdZ
如您所见,.message-actiondiv似乎在.message-bodydiv 之下。