例如,我有这样的模型:
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public BlogImage BlogImage { get; set; }
}
public class BlogImage
{
public int BlogImageId { get; set; }
public byte[] Image { get; set; }
public string Caption { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想在ImageView视图中返回Url和Image.
我在哪里需要创建和定义SQL视图?
例如,我有这些实体:
public class Book
{
[Key]
public string BookId { get; set; }
public List<BookPage> Pages { get; set; }
public string Text { get; set; }
}
public class BookPage
{
[Key]
public string BookPageId { get; set; }
public PageTitle PageTitle { get; set; }
public int Number { get; set; }
}
public class PageTitle
{
[Key]
public string PageTitleId { get; set; }
public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我只知道BookId,我应该如何加载所有PageTitles?
这是我试图这样做的方式:
using (var dbContext …Run Code Online (Sandbox Code Playgroud) 例如,我有3个类,我用它们用于多对多关系:
public class Library
{
[Key]
public string LibraryId { get; set; }
public List<Library2Book> Library2Books { get; set; }
}
public class Book
{
[Key]
public string BookId { get; set; }
public List<Library2Book> Library2Books { get; set; }
}
public class Library2Book
{
public string BookId { get; set; }
public Book Book { get; set; }
public string LibraryId { get; set; }
public Library Library { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
它们配置为ApplicationDbContext:
protected override void …Run Code Online (Sandbox Code Playgroud) 我有两个项目:
如何IStringLocalizer在MyServices中添加本地化?.resx文件必须在哪里?
我想在控制器中更改sql连接字符串,而不是在ApplicationDbContext中.我正在使用Asp.Net Core和Entity Framework Core.
例如:
public class MyController : Controller {
private readonly ApplicationDbContext _dbContext
public MyController(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
}
private void ChangeConnectionString()
{
// So, what should be here?
} }
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有这样的项目结构:
- MyApp
`- firstFolder
`- firstFile.js
`- secondFolder
`- thirdFolder
`- thirdFile.js
Run Code Online (Sandbox Code Playgroud)
我如何firstFile.js从导入thirdFile.js?
像import myFunc from '../firstFolder/firstFile';in 之类的东西thirdFile.js不起作用。
当我尝试添加迁移时dnx ef migrations add Mig,控制台中出现以下异常:
尝试激活“NewLibrary.Models.ApplicationDbContext”时无法解析“Microsoft.AspNet.Http.IHttpContextAccccessor”类型的服务。
我的ApplicationDbContext:
public class ApplicationDbContext : DbContext
{
private readonly IHttpContextAccessor _accessor;
public ApplicationDbContext(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么问题?
我应该如何正确地向ApplicationDbContext构造函数添加依赖项?
我有简单的 POCO 类:
public class Library
{
[Key]
public string LibraryId { get; set; }
public string Name { get; set; }
public List<Book> Books { get; set; }
}
public class Book
{
[Key]
public string BookId { get; set; }
public string Name { get; set; }
public string Text { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有查询,返回包含已包含书籍的图书馆:
dbContext.Set<Library>.Include(x => x.Books);
Run Code Online (Sandbox Code Playgroud)
我试图跳过 5 个库,然后选择其中的 10 个:
await dbContext.Set<Library>.Include(x => x.Books).Skip(5).Take(10).ToListAsync();
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试在此查询上执行Skip和Take方法时,它返回没有包含书籍列表的图书馆。
如何使用Skip和Take保存以前包含的实体?
我有表格,有两个按钮:
<form action="/Book/Crud" method="post">
<input type="text" name="bookInput" />
<button type="submit">Save</button>
<button type="submit">Save and exit</button>
</form>Run Code Online (Sandbox Code Playgroud)
我如何传递给我的控制器,或者其他值,这取决于按钮?
<button type="submit" ?????? >Save</button>这里应该有什么?
我正在使用 Asp.Net Core 和这个控制器:
public IActionResult Crud(string bookInput)
{
//removed code for brevity
}
Run Code Online (Sandbox Code Playgroud) 我有简单的 url 重写器:
private static void RedirectToAPI(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value.StartsWith("/apiendpoint", StringComparison.OrdinalIgnoreCase))
{
var json = JsonConvert.SerializeObject(request.Path.Value
.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
.Skip(1));
var response = context.HttpContext.Response;
response.Headers[HeaderNames.Location] = $"/custom";
response.StatusCode = StatusCodes.Status301MovedPermanently;
context.Result = RuleResult.EndResponse;
using (var bodyWriter = new StreamWriter(response.Body))
{
bodyWriter.Write(json);
bodyWriter.Flush();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当它重定向到/custom url 时,请求有方法 GET,而这个方法需要 POST。
比如发送 GET 请求到 url /apiendpoint/first/second/third,然后 rewriter 响应重定向,相应地,下面的请求必须是 POST 方法,但现在,它是 GET。
如何更改请求方法,即在 url 重写器响应之后?
c# ×8
asp.net-core ×5
.net-core ×1
asp.net ×1
commonjs ×1
dll ×1
html ×1
javascript ×1
many-to-many ×1
redirect ×1
requirejs ×1
url ×1