我正在使用AutoMapper来投影以下结构
public class OuterSource
{
....
public Guid? InnerId { get; set }
public InnerSource Inner { get; set; }
}
public class InnerSource
{
public Guid Id { get; set; }
public DateTime Date { get; set; }
}
public class OuterDest
{
....
public InnerDest Inner { get; set; }
}
public class InnerDest
{
public Guid Id { get; set; }
public DateTime Date { get; set; }
}
var result = AutoMapper.Project<OuterSource, OuterDest>(query);
Run Code Online (Sandbox Code Playgroud)
如您所见,Inner对象可以为空.
如果Inner对象具有值,则投影工作正常,但如果Inner对象为null,则EF将抛出异常,就好像它不理解InnerDest实际上应为null.
"The …Run Code Online (Sandbox Code Playgroud) 我有以下文件:
自动建议组件.tsx:
import * as React from 'react';
interface AutosuggestProps {
...
}
interface AutosuggestState {
...
}
export default class Autosuggest extends React.Component<AutosuggestProps, AutosuggestState> {
...
}
Run Code Online (Sandbox Code Playgroud)
我想在 ConsumerComponent.tsx 中导入这样的 Autosuggest 组件:
import Autosuggest = Components.AutoSuggest;
Run Code Online (Sandbox Code Playgroud)
如何导出 AutosuggestComponent.tsx 才能完成这项工作?
我尝试创建一个 Autosuggest.ts,如下所示:
import AutosuggestComponent from './AutosuggestComponent';
namespace Components {
export const Autosuggest = AutosuggestComponent;
}
Run Code Online (Sandbox Code Playgroud)
这是行不通的。然后 ConsumerComponent 无法找到命名空间“Components”。然而,这有效:
// import AutosuggestComponent from './AutosuggestComponent';
namespace Components {
export const Autosuggest = { dummyValue: "test" }
}
Run Code Online (Sandbox Code Playgroud)
一旦我注释掉导入,ConsumerComponent 就能够找到名称空间。为什么?
有什么办法可以解决这个问题吗?
在我的ASP.NET核心项目中,我试图像这样提供一个html文件:
public IActionResult Index()
{
return File("c:/path/to/index.html", "text/html");
}
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
FileNotFoundException: Could not find file: c:/path/to/index.html
Run Code Online (Sandbox Code Playgroud)
将ErrorMessage的路径粘贴到我的浏览器中,我可以打开文件,因此文件显然就在那里.
我能够提供文件的唯一方法是将它放在项目文件夹中的wwwroot中,并按照以下方式提供:
public IActionResult Index()
{
return File("index.html", "text/html");
}
Run Code Online (Sandbox Code Playgroud)
我已经更改了我使用的静态文件的文件夹app.UseStaticFiles(options)(有效),所以我认为Controller会使用该文件夹作为默认值,但它会继续查找wwwroot.
如何从Controller中提供位于wwwroot之外,甚至是项目之外的文件?
我们已经使用 React 和 jsx 一段时间了,对于条件我们一直在使用我非常喜欢的 jsx-control-statements:
<If condition={something === true}>
<div>Something</div>
</If>
Run Code Online (Sandbox Code Playgroud)
最近我们的项目已经转移到 TypeScript,这很好,但是 jsx-control-statements 不再有效。原因是条件表达式不是 React 组件,而是在编译阶段由 Babel 处理,这意味着 TypeScript 不会编译。
我有哪些选择?
我想制作一个 If 组件,但它需要我将结果包装在一个我不喜欢的新元素中。
将我的 .NET Core 项目移至解决方案中的子文件夹后,我无法再使用 VS Code 对其进行调试。
如果我移动tasks.json到launch.json项目文件夹并打开 VS Code,我就可以进行调试,但我希望能够在 VS Code 中打开整个解决方案。
我收到的错误消息是这样的:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
该错误似乎表明我的任务运行程序无法再找到我的项目,因此我尝试将其添加到tasks.json:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
],
// My addition
"options": {
"cwd": "${workspaceRoot}/myProjectFolder"
}
}
Run Code Online (Sandbox Code Playgroud)
这样做我可以启动任务,但随后出现以下错误:
Exception thrown: …Run Code Online (Sandbox Code Playgroud) 我正在使用CsvTypeProvider将CSV文件中的数据映射到我自己的数据结构中.这非常有效,除了我必须每次都重复映射功能:
type GamesFile = CsvProvider<"./data/15.csv">
let games15 = GamesFile.Load("./data/15.csv").Rows |> Seq.map ( fun c -> { Division = c.Div; Date = c.Date; HomeScore = c.HomeScore; AwayScore = c.AwayScore })
let games16 = GamesFile.Load("./data/16.csv").Rows |> Seq.map ( fun c -> { Division = c.Div; Date = c.Date; HomeScore = c.HomeScore; AwayScore = c.AwayScore })
Run Code Online (Sandbox Code Playgroud)
当我尝试将它移动到一个函数时,我被告知"基于此程序点之前的信息查找不确定类型的对象.在此程序点之前可能需要类型注释来约束对象的类型.这可能允许解析查找."
这是有道理的,但是如何从CSV的内容推断类型时,如何告诉映射函数它是什么类型?这通常如何解决?
我们在本地IIS Express上运行带有ASP.NET Core的Web API.我们正在使用hosts-file中配置的自定义域名.
这很好用,但我们必须时不时地手动信任Chrome中的网站,因此我们希望将IIS Express设置为使用我们的SSL证书.
IIS Express在launchSettings.json中配置:
"iisExpress": {
"applicationUrl": "http://applocal.ourdomain.com:5000",
"sslPort": 44300
}
Run Code Online (Sandbox Code Playgroud)
我们如何配置IIS Express以使用我们的SSL证书?
我正在使用ASP.NET Core来提供这样的SPA:
[<Route("{*url}")>]
member this.Index () =
this.View("~/wwwroot/Index.cshtml")
Run Code Online (Sandbox Code Playgroud)
我的JSON端点位于同一个应用程序中,路由如下:
[<Route("api/something/{somethingId:int})>]
Run Code Online (Sandbox Code Playgroud)
这工作正常,除了当我尝试调用端点时,api/something/that/doesnt/exist我得到索引页面,当我真正想要404.
是否可以以[<Route("{*url}")>]这样的方式设置它排除以"api"开头的任何URL?
asp.net routing asp.net-core-mvc asp.net-core asp.net-core-webapi
我创建了一个辅助函数,用于从我的 Giraffe 项目返回 Thoth.Json 样式的 json,该函数接受Result<'a,'b>并返回 JSON。
let json result next (ctx: HttpContext) =
match result with
| Ok result ->
(setHttpHeader "Content-Type" "application/json" >=>
setBodyFromString (Encode.Auto.toString (0, result))) next ctx
| Error e -> ...
Run Code Online (Sandbox Code Playgroud)
这工作正常,直到我返回Ok (),它编译并且应该完全有效。
然而,Thoth.Json 不太喜欢它:
Cannot generate auto encoder for Microsoft.FSharp.Core.Unit. Please pass an extra encoder.
我怎样才能检查是否result是一个unit或使自动编码器句柄unit?
我在 Postgres 中使用 Dapper,我想记录一些诊断信息,尤其是正在运行的实际查询。
如果我使用的是 SQL Server,我会这样做
let connection = new SqlConnection(connectionString)
connection.StatisticsEnabled = true
// run query
let stats = connection.RetrieveStatistics()
Run Code Online (Sandbox Code Playgroud)
但我似乎找不到类似的东西NpgsqlConnection。
检索正在运行的实际查询的最佳方法是NpgsqlConnection什么?
我正在尝试使用 F# 设置 EF Core。我的 DbContext 看起来像这样
type MainContext(options : DbContextOptions<MainContext>) =
inherit DbContext(options)
[<DefaultValue()>] val mutable dokumenter : DbSet<Dokument>
member x.Dokumenter with get() = x.dokumenter and set v = x.dokumenter <- v
Run Code Online (Sandbox Code Playgroud)
在 Startup.fs 中:
member this.ConfigureServices(services: IServiceCollection) =
services.AddDbContext<MainContext>(fun options -> options.UseInMemoryDatabase()) |> ignore
Run Code Online (Sandbox Code Playgroud)
这给出了以下编译错误:
No overloads match for method 'AddDbContext'. The available overloads are shown below (or in the Error List window).
我究竟做错了什么?
asp.net-core ×4
c# ×4
f# ×4
asp.net ×2
reactjs ×2
typescript ×2
.net ×1
.net-core ×1
automapper ×1
dapper ×1
f#-data ×1
f#-giraffe ×1
fable-f# ×1
iis-express ×1
npgsql ×1
react-jsx ×1
routing ×1
ssl ×1