小编Sau*_*abh的帖子

如何更新 Entity Framework Core 中的 DBContext 类

我在我的项目中使用Entity Framework Core,使用命令创建了一个DbContext类

\n\n
PM> Scaffold-DbContext "Server=servername;Database=DBname;User Id=user;Password=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context QuestionnaireEntities -Tables Category_Master,Item,Option_Master,Question_Master,Sub_Category_Master,Sub_Item\n
Run Code Online (Sandbox Code Playgroud)\n\n

它完美地创建了 DBContext 类,但是如果我想从数据库更新我的 DBContext,而不是在 EFcore 中执行此操作,在 EF 中只需右键单击并选择选项更新从数据库即可轻松完成

\n\n

另外,我如何在 DBContext 类中使用存储过程

\n\n

在msdn网站上他们提到了一个命令

\n\n
\n

PM> get-helpscaffold-dbcontext\xe2\x80\x93详细

\n
\n\n

但它没有任何有关更新 DBContext 和在其中添加存储过程的信息

\n\n

我如何在 EF Core 中执行此操作\n我正在使用带有 .Net core 2.0 和 EFcore 2.0 的 VS 2017 社区版

\n

.net-core ef-core-2.0

6
推荐指数
1
解决办法
1万
查看次数

Blazor 组件文件中的依赖注入

我的应用程序中有一个 blazor 组件:

public class IndexComponent : ComponentBase
{
    public string ContentRoot { get; set; }
    public string WebRoot { get; set; }
    private IHostingEnvironment HostingEnvironment;

    public IndexComponent(IHostingEnvironment hostingEnvironment)
    {
        HostingEnvironment = hostingEnvironment;
    }

    protected override async Task OnInitAsync()
    {
        //Some Code Here
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试在我的应用程序中使用 DI,例如 IHostingEnvironment。

代码在这里没有给出编译时错误,但是当我运行它时,它比在这个剃刀的文件后面的代码(Index.razor.g.cs 文件)中:

public class Index : IndexComponent
Run Code Online (Sandbox Code Playgroud)

在这一行它说:

没有给出对应于 IndexComponent.IndexComponent 的所需形式参数托管环境的参数

这可以通过在 Razor 文件中使用 @inject IHostingEnvironment 来解决,但我正在将我的功能块从 Razor 移动到 IndexComponent.cs 文件,因此需要它。

它都没有以下方式工作:

[Inject]
IHostingEnvironment HostingEnvironment
Run Code Online (Sandbox Code Playgroud)

什么会在这里工作?

注意:不使用 ViewModel

更新 1

在 StartUp.cs …

c# asp.net-core blazor blazor-client-side

6
推荐指数
2
解决办法
5657
查看次数

在 ASP.NET Blazor 中读取静态文件

我有一个客户端 Blazor 应用程序。我想appsetting.json为我的客户端配置创建一个文件,就像我们environment.ts在 Angular 中有一个文件一样。

为此,我在其中保留了一个ConfigFiles文件夹wwwroot和一个 JSON 文件。我正在尝试阅读此文件,如下所示。

首先获取路径:

public static class ConfigFiles
{
    public static string GetPath(string fileName)
    {
        return Path.Combine("ConfigFiles", fileName);
    }
}
Run Code Online (Sandbox Code Playgroud)

比阅读它:

public string GetBaseUrl()
{
    string T = string.Empty;
    try
    {
        T = File.ReadAllText(ConfigFiles.GetPath("appsettings.json"));
    }
    catch (Exception ex)
    {
        T = ex.Message;
    }
    return T;
}
Run Code Online (Sandbox Code Playgroud)

但我总是收到错误:

找不到路径“/ConfigFiles/appsettings.json”的一部分。

GetPath()方法里面,我也试过:

return Path.Combine("wwwroot/ConfigFiles", fileName);
Run Code Online (Sandbox Code Playgroud)

但我仍然得到同样的错误:

找不到路径“wwwroot/ConfigFiles/appsettings.json”的一部分。

由于IHostingEnvironment在客户端 Blazor 中没有概念,那么这里读取静态 JSON 文件的正确方法是什么?

asp.net-core blazor asp.net-core-3.0 .net-core-3.0 blazor-client-side

4
推荐指数
1
解决办法
3570
查看次数

将模型导出到数据表

我想将我的模型数据转换为DataSetDataTable(以 excel 格式导出)

db.EMPs.ToList()
Run Code Online (Sandbox Code Playgroud)

dbDataContextEMPsdataclass

如何将此列表导出到DataTable,我可以将行导出到 excel 但如何从标题访问列名(不应在 中手动添加列名DataTable

c# linq asp.net-mvc entity-framework

3
推荐指数
1
解决办法
5889
查看次数

在 ngFor , Angular5 中增加 2

我在 Angular 5 中有一段带有 ngFor 的代码,如下所示

角度模型

 export class UserReviews {
  public PageName: string;
  public UserName: string;
  public Review: string;
  public Rating: number;
  public IsApproved: boolean;
}
Run Code Online (Sandbox Code Playgroud)

变量

UserReviewModel: UserReviews = new UserReviews();
UserReviewList: UserReviews[] = [];
this.UserReviewList = [
      {
        PageName: "Page Name Here",UserName: "User1",Review:"Review Here",
        Rating: 3,IsApproved: true
      },
      {
        PageName: "Page Name Here",UserName: "User2",Review:"Review Here",
        Rating: 4,IsApproved: true
      },
      {
        PageName: "Page Name Here",UserName: "User3",Review:"Review Here",
        Rating: 3, IsApproved: true
      },
      {
        PageName: "Page Name Here",UserName: "User4",Review:"Review …
Run Code Online (Sandbox Code Playgroud)

angularjs angular

2
推荐指数
1
解决办法
528
查看次数

如何在Blazor.Net中将代码与UI分开

引用此VisualStudioMagazine文章,我试图将代码放在单独的文件中,而不是剃刀视图中。

我试过了:

@page "/Item"
@using WebApplication1.Shared
@using WebApplication1.Client.Services;
@inject HttpClient Http
@inherits ItemComponent

@if (ItemList != null)
{
    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Category</th>
                <th>Metal</th>
                <th>Price</th>
                <th>Quantity</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in ItemList)
            {
                <tr>
                    <td>@item.ID</td>
                    <td>@item.Name</td>
                    <td>@item.Category</td>
                    <td>@item.Metal</td>
                    <td>@item.Price</td>
                    <td>@item.Quantity</td>
                </tr>
            }
        </tbody>
    </table>
}

@functions{
    public ItemModel[] ItemList;
    ItemComponent IC = new ItemComponent();

    protected override async Task OnInitAsync()
    {
        ItemList = IC.GetItems().Result;
        //ItemList = await Http.GetJsonAsync<ItemModel[]>("api/Item/GetItems");
        StateHasChanged();
    }
}
Run Code Online (Sandbox Code Playgroud)

和ItemComponent:

using System.Threading.Tasks;
using …
Run Code Online (Sandbox Code Playgroud)

c# blazor blazor-server-side asp.net-core-3.0 .net-core-3.0

2
推荐指数
4
解决办法
1477
查看次数

网站在 IIS 中不可见

在 IIS 管理器中,我只看到添加连接,其他选项(例如默认网站、添加新网站)不可用。尽管一切都按顺序安装(通过“打开或关闭 Windows 功能”进行检查)。

在此输入图像描述

其Windows 10和IIS版本如下

在此输入图像描述

任何线索,如何在 IIS 中获取默认网站或在此处添加新网站?

iis web-hosting iis-10 asp.net-core-webapi

1
推荐指数
1
解决办法
2348
查看次数

如何将一行数据从控制器传递到视图,而不是IEnumerable <>

我想从控制器发送数据到视图

EMP e =(EMP) db.EMPs.Where(n => n.id == j);
return View(e);
Run Code Online (Sandbox Code Playgroud)

EMPModel对象.错误是

无法转换System.Data.Entity.Infrastructure.DbQuery`1 [WebApplication1.Models.EMP]类型的对象以键入WebApplication1.Models.EMP

注意:我不能用 IEnumerable<Model>

c# linq asp.net-mvc entity-framework

0
推荐指数
1
解决办法
156
查看次数