我在我的项目中使用Entity Framework Core,使用命令创建了一个DbContext类
\n\nPM> 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\n\nPM> get-helpscaffold-dbcontext\xe2\x80\x93详细
\n
但它没有任何有关更新 DBContext 和在其中添加存储过程的信息
\n\n我如何在 EF Core 中执行此操作\n我正在使用带有 .Net core 2.0 和 EFcore 2.0 的 VS 2017 社区版
\n我的应用程序中有一个 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 …
我有一个客户端 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
我想将我的模型数据转换为DataSet
或DataTable
(以 excel 格式导出)
db.EMPs.ToList()
Run Code Online (Sandbox Code Playgroud)
db
是DataContext
,EMPs
是dataclass
。
如何将此列表导出到DataTable
,我可以将行导出到 excel 但如何从标题访问列名(不应在 中手动添加列名DataTable
)
我在 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) 引用此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) 在 IIS 管理器中,我只看到添加连接,其他选项(例如默认网站、添加新网站)不可用。尽管一切都按顺序安装(通过“打开或关闭 Windows 功能”进行检查)。
其Windows 10和IIS版本如下
任何线索,如何在 IIS 中获取默认网站或在此处添加新网站?
我想从控制器发送数据到视图
EMP e =(EMP) db.EMPs.Where(n => n.id == j);
return View(e);
Run Code Online (Sandbox Code Playgroud)
这EMP
是Model
对象.错误是
无法转换System.Data.Entity.Infrastructure.DbQuery`1 [WebApplication1.Models.EMP]类型的对象以键入WebApplication1.Models.EMP
注意:我不能用 IEnumerable<Model>
c# ×4
blazor ×3
asp.net-core ×2
asp.net-mvc ×2
linq ×2
.net-core ×1
angular ×1
angularjs ×1
ef-core-2.0 ×1
iis ×1
iis-10 ×1
web-hosting ×1