如何首先使用Entity Framework代码和linq查询多对多关系?问题是EF自动创建关系表.所以,我没有在我的背景下.
这是关系模型:

我需要一个特定Category_Id的文章列表,基本上复制类似的东西:
select a.Id, a.Title,a.ShortDescription
from Articles a
join CategoryArticles ca on ca.Article_Id=a.Id
where ca.Category_Id = @parameter
Run Code Online (Sandbox Code Playgroud)
但是我的dbcontext只有:
public DbSet<Article> Articles { get; set; }
public DbSet<Category> Categories { get; set; }.
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我正在使用bootstrap作为站点标题.如果我想使网站的徽标响应,我应该有两个徽标图像(一个用于桌面,一个用于移动)或者我应该调整我的图像徽标吗?获得它的最佳方法是什么?谢谢.那是我的代码:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid"></div>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src="~/Content/images/logo.png" /></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="/">Home</a></li>
<li><a href="~/About/Index">About</a></li>
<li><a href="~/Contact/Index">Contacts</a></li>
</ul>
</div>
</nav>
Run Code Online (Sandbox Code Playgroud) 我试图理解Ajax请求中的accept和dataType之间的区别.文件说明:
接受(默认值:取决于DataType)类型:PlainObject在请求标头中发送的内容类型,它告诉服务器它将接受哪种响应.
dataType(默认值:Intelligent Guess(xml,json,script或html))类型:String您希望从服务器返回的数据类型.
基本上,它是一样的吗?它有相同的目的.
我已经构建了一个在ASP.NET Core中使用JWT承载认证的应用程序.在进行身份验证时,我定义了一些我需要在另一个WebAPI控制器中读取的自定义声明,以便执行某些操作.
任何想法我如何实现这一目标?
我的代码如下所示:(代码已经简化)
public async Task<IActionResult> AuthenticateAsync([FromBody] UserModel user)
{
..............
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim("userSecurityKey", userDeserialized.SecurityKey.ToString()),
new Claim("timeStamp",timeStamp),
new Claim("verificationKey",userDeserialized.VerificationKey.ToString())
}),
Expires = DateTime.UtcNow.AddDays(7),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key),
SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);
.................
}
Run Code Online (Sandbox Code Playgroud)
另一个控制器:(需要阅读"verificationKey"声明.)
[HttpGet]
[Route("getcandidate")]
public async Task<IActionResult> GetCandidateAsync()
{
try
{
............
var verificationKey = //TODO: GET VerificationKey FROM THE …Run Code Online (Sandbox Code Playgroud) 我在IIS中托管了一个角度应用程序.为了将所有请求重定向到应用程序的根目录并允许角度路由处理不同的路由,我添加了一个带有URL Rewrite规则的web.config文件,如下所示:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
它工作正常.但是,我现在需要强制应用程序从HTTP重定向到HTTPS.为了做到这一点,我可以添加一个新规则,如下面的帖子描述的:Angular 2 - 总是重定向到https://而不是使用http://
规则强制HTTPS:
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
此规则也适用,但它将我的重定向分解为先前定义的根规则.那么有没有人有一个想法我如何将这两个规则混合在一起或以其他方式实现这两个目的?
如何使用Angular-material验证表单,我需要两个功能:1)如果必填字段为空,请单击"提交时显示错误消息".2)如果表单字段无效,请勿发送帖子请求(避免提交).下一个代码避免提交,但是在单击时它不显示错误消息,仅当光标离开每个输入字段时.
<form name="userForm">
<md-input-container>
<input name="email" placeholder="Email" data-ng-model="vm.registerUserData.email" required />
<div ng-messages="userForm.email.$error" ng-if='userForm.myControl.$dirty'>
<div ng-message="required">This is required!</div>
</div>
</md-input-container>
<md-input-container>
<input name="Password" placeholder="Password" data-ng-model="vm.registerUserData.password" required />
<div ng-messages="userForm.Password.$error">
<div ng-message="required">This is required!</div>
</div>
</md-input-container>
<md-input-container>
<md-button id="registerUser" value="Register" class="md-raised md-primary" ng-click="userForm.$valid && vm.registerUser()" aria-label="login" ng-disabled="login.loginForm.$invalid()">
Create
</md-button>
</md-input-container>
</form>
Run Code Online (Sandbox Code Playgroud) 我试图从父组件检查放置在子组件上的表单的有效性.最好的方案是在表单无效时禁用父组件上的按钮,或者在更糟糕的情况下,如果表单无效则从父按钮触发警报.
我可以使用@ViewChild装饰器检查表单是否具有来自父级的'ng-invalid'类来调用子组件上的函数,如下所示:
父组件:
export class CandidateVerificationComponent implements OnChanges, OnInit {
@ViewChild(RightPanelComponent) rightPanelPointer: RightPanelComponent;
saveAndFinish() {
if (this.rightPanelPointer.checkFormValidity())
{
alert('No Valid');
return;
}
this.rightPanelPointer.onSubmit();
}
}
Run Code Online (Sandbox Code Playgroud)
子组件:
export class RightPanelComponent implements OnChanges , OnInit{
@ViewChild("candiateForm", { read: ElementRef }) tref: ElementRef;
checkFormValidity():boolean {
return (this.tref.nativeElement.className.indexOf('ng-invalid') !== -1);
}
}
Run Code Online (Sandbox Code Playgroud)
它适用于最糟糕的情况,但我不喜欢将组件链接到DOM的想法,我宁愿更聪明的想法.
我想使用模板引用变量(#candiateForm),例如允许从表单(子)中检查提交按钮(见下文)中的有效性,以便检查父项的有效性.是否可以从父级访问该模板变量?
<form (ngSubmit)="onSubmit()" #candiateForm="ngForm" name="candiateForm" (change)="formChanged()">
<div class="form-group">
<label class="control-label" for="firstName">First name:</label>
<input type="text" class="form-control" id="firstName" pattern="^[^0-9]+$" required [(ngModel)]='candidate.firstName' name="firstName" #firstName="ngModel">
</div>
<button type="submit" class="btn btn-default" [disabled]="!candiateForm.form.valid">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud) 如何证明不同断点的列内容合理。例如,我希望以下电子邮件文本在>中等列的情况下被对齐到末尾,而在较小列的情况下被对齐到中间。寻找一个优雅的解决方案。
<div class="row">
<div class="col-md-4">
Email
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我使用 kotlin.logging 作为应用程序的日志记录框架。
我希望能够以更易读的方式(可能是 JSON 格式)记录堆栈跟踪:
我正在执行以下操作,但会导致非常冗长/不可读的格式:
logger.error("Exception caught in handleIllegalArgumentsException: $e", e.printStackTrace())
Run Code Online (Sandbox Code Playgroud)
仅记录 Throwable 异常时(见下文),它不显示堆栈跟踪:
logger.error("Exception caught in handleIllegalArgumentsException: $e")
Run Code Online (Sandbox Code Playgroud) 我已经在 Spring boot 应用程序中配置了 Swagger,spring boot 应用程序有 2 个控制器,casesController 和 AttachmentController,我希望附件控制器中的所有端点都出现在 case 控制器端点之后,但 swagger 正在做相反的事情。
我的代码如下所示:
配置文件:
@Configuration
class OpenApiConfig(
@Value("\${springdoc.info.title}") val title: String,
@Value("\${springdoc.info.description}") val infoDescription: String,
@Value("\${springdoc.info.version}") val version: String,
@Value("\${springdoc.info.license.name}") val licenseName: String,
@Value("\${springdoc.info.license.url}") val licenseUrl: String,
@Value("\${springdoc.info.contact.email}") val email: String,
@Value("\${springdoc.server.url}") val url: String,
@Value("\${springdoc.server.description}") val description: String
) {
@Bean
fun customOpenAPIConfig(): OpenAPI {
return OpenAPI()
.components(
Components()
)
.info(
Info().title(title).description(infoDescription).version(version)
.license(License().name(licenseName).url(licenseUrl))
.contact(Contact().email(email))
)
.servers(listOf(Server().url(url).description(description)))
.tags(listOf(Tag()))
}
}
Run Code Online (Sandbox Code Playgroud)
附件控制器:
@RestController
@RequestMapping("/cases/{id}/attachments")
lass AttachmentController(private …Run Code Online (Sandbox Code Playgroud) angular ×2
c# ×2
kotlin ×2
spring-boot ×2
ajax ×1
angularjs ×1
asp.net-core ×1
bootstrap-4 ×1
css ×1
exception ×1
html ×1
https ×1
iis ×1
java ×1
jquery ×1
jwt ×1
linq ×1
many-to-many ×1
navbar ×1
openapi ×1
redirect ×1
swagger ×1
typescript ×1