我正在尝试创建一个托管的ASP.net Blazor应用程序,并试图将一个记录器放到我的控制器中。
我有这个:
public MyController(ILogger logger) {
_logger = logger;
// more initialization
}
但当我运行它时,我得到:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the reque
我想修改我的数据库表的一个列(通知表)。相关的通知Id由视图确定,并使用Ajax调用发送回控制器。我的控制器代码:
[HttpPost]
public JsonResult UpdateNotification(int notificationId, int userId)
{
string notificationText = _notificationRepository.GetNotificationById(notificationId).isSeen;
var myNotification = new N
我正在使用ASP.NET Core5Web API,并尝试使用新的作为我的模型类。但每当我使用with表达式更新修改后的模型时,我都会收到关于跟踪问题的EF核心错误:
System.InvalidOperationException: The instance of entity type 'Product' cannot be
tracked because another instance with the key value '{ID: 2}' is already being
tracked. When attaching existing entiti
我目前有一个ASP.NET Web 2应用程序,为了这个问题,它管理“项”。ASP.NET标识2用于为请求提供身份验证,数据由实体框架6传递。
我的目标是将项目的所有者属性自动设置为验证POST请求的用户。以下是目前为止的代码:
public async Task<IHttpActionResult> PostItem(Item item)
{
var userId = User.Identity.GetUserId();
var user = await UserManager.FindByIdAsync(userId);
// S
型号:
public class Client{
public int Id {get;set;}
public string Name {get;set;}
public Address Address {get;set;}
public int AddressId {get;set;}
}
public class Address{
public int Id
public string Address1 {get;set;}
public string PostCode {get;set;}
}
视图模型:
public
public JsonResult CreateOrder([FromBody]CustomerOrderModel orderModel)
{
var customer = _customerService.GetCustomer(orderModel.customerid);
var order = new OrderViewModel();
order.Customer = customer;
order.OrderPlacedOn = DateTime.Now;
order.OrderForCustomer = customer.Busine
我有以下课程:
顺序:
public class Order {
private Order()
{
//some code to initialise object
}
//more properties
public Prepayment Prepayment { get; private set; }
//more methods and properties
}
预付:
public class Prepayment:ValueObject<Prepayment>
{
private Prepayment()
{
我正在使用DataServiceContext加载一些实体投影(实体有许多属性,为了最小化流量,我只加载那些属性,这些属性是目前需要的),如下所示:
from x in ctx.Portfolios
select new
{
Id = x.Id,
Name = x.Name,
PortfolioName = x.PortfolioName,
Description = x.Description,
ValidFrom = x.ValidFrom,
Valid
在我的ASP.NET核心应用程序中,我有DbContext,它包含两种类型的实体,比如小学生和班级。我想要增加一个新的班级,获得新班级的Id,并增加一个新的学生到班级。我试过这样做:
var Class = new Class{ name = "Math" };
Context.Classes.Add(Class);
await Context.SaveChangesAsync();
var Pupil = new Pupil{ name = "Rem", ClassId = Class.Id };
Context.Pupils.Add(Pupil);
awai
我在ASP.NET核心应用程序上使用带有ASP.NET扩展的实体框架。我的一个域模型Message具有Guid属性,当我想在DbContext上执行任何操作时,我会收到一个错误:The property 'Message.ID' is of type 'Guid' which is not supported by current database provider. Either change the property CLR type or manually configure the database type for it.。
我如何“手动配置数据库类型
我有两张桌子Client和ClientSecret。这些表格的结构如下:
public class Client
{
public int Id { get; set; }
public string ClientId { get; set; }
public string ClientName { get; set; }
public List<ClientSecret> ClientSecrets { get; set; }
}
public class ClientSecret
{
pu
在尝试添加迁移时,我得到了以下错误:
PS C:\Code\morpher.ru\Morpher.Database> dotnet ef migrations add AddQazaqFeatures --startup-project=../Morpher.Database.Design
Build started...
Build succeeded.
System.InvalidOperationException: The association between entity types 'Service' and 'Deployment' has
我正在使用ASP.NET WebApi 2和实体框架6.1.0-字母1编写一个简单的"Todo应用程序“。我的目标是限制访问,每个用户只能查看/编辑他们自己的待办事项。
示例:
// GET api/Todo/5
[ResponseType(typeof(Todo))]
public async Task<IHttpActionResult> GetTodo(int id)
{
var todo = await _db.Todos.FindAsync(id);
if (todo == null)
我在我的asp.net应用程序中使用实体框架6,并使用原始查询,如下所示:
string studentName = ctx.Database.SqlQuery<string>(
"Select studentname from Student where studentid=1").FirstOrDefault();
现在,我将我的应用程序移到asp.net核心,但是如果不使用DbSet类型,就无法找到原始的sql查询。
var students = context.Students
.FromSql("
我使用的是ASP.NET MVC6和实体框架7。
我的模型:
public class Contact {
public int[] SelectedEstimator { set; get; }
}
我得到以下错误:
System.InvalidOperationException: The property 'SelectedEstimator'
on entity type 'ContactsManagerV3.Models.Contact'
has not been added to the model or ignored.
如果我将Se
我正在构建ASP.Net核心应用程序,这取决于这个干净的示例,它使用MediatR来执行命令。我希望在我的应用程序中使用ASP.Net核心标识,所以在我的CreateUserCommandHandler中,我想使用UserManager添加新用户,但是当我将UserManager添加到命令承包商MediatR时,无法创建处理程序,并且在此例外情况下失败:
System.InvalidOperationException: Error constructing handler for request of type MediatR.IRequestHandler`2[GoGYM.Applicat
我试图使用实体框架7更新一个外键,但是它产生了错误:在对象'X‘中找不到属性'Y’。我尝试过许多不同的解决方案,但仍然没有奏效。示例代码:
class X
{
property Y {get; set;} -> property Y is a foreign key and also a complex type
}
在表'X‘中,我们有一个列'Y_ID’,它是外键。
注意:我只想更新外键。例如,最初的类'X‘指向'NULL',我想更新类'X’以指向'Y1'。
实体框架7代码:
var x = this.
我的对象的简化版本:
public class CV
{
public int Id {get;set;}
public string Name {get;set;}
public List<Certificate> Certificates {get;set;}
public List<Experience> Experiences {get;set;}
}
public class Certificate
{
public int Id {get;set;}
public string Name {get;set;}
}
public c
我有一个实体Product和一个ValueObject Money。
public class Product
{
public Product() { }
[Key]
public int Id { get; set; }
public string Name { get; set; }
public Money Price { get; set; }
}
public class Money : BaseValueObject
{
public Money(string currency, decimal amount)
{
我无法添加交易实体,因为买卖双方都在引用同一个城市"City1“。我在这里处理分离的实体,因为我通过API接收整个模型。
// This is the result of Deal entity deserialization
var deal = new Deal
{
Id = "D1",
Buyer = new Person
{
Id = "P1",
Name = "Person1",
City = new City { Name = "City1"
我有一个简单的ASP.NET托管的WCF服务,它有几个方法,当涉及到使用实体框架时,这些方法都具有相同的模式...
public void Operation1(string username)
{
using(MyEFContext context = new MyEFContext())
{
UserInfo info = (from ui in context.UserInfos
where ui.User.Equals(username)
select u
在迁移到ASP.Net核心之前,我使用了Ninject,它允许我以通用的方式注入实体框架数据库上下文。例如:
Bind<DbContext>().To<MyActualDbContext>();
在ASP.Net Core中,当使用AddDbContext时,如果我执行以下操作,则会导致服务无法解决。
AddDbContext<MyActualDbContext>(x=> x.UseSqlServer("..."));
---
public class TestController: Controller {
public Db
运行asp.net应用程序时,该应用程序调用承载在sql server中的存储过程,sql clr返回以下错误:-
An error occurred: A .NET Framework error occurred during execution of user-defined routine or aggregate "Procedure Name":
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection
我尝试为Asp.net核心DBContext实现一个Asp.net测试,但是我得到了以下错误。
消息: System.InvalidOperationException :无法跟踪实体类型'Ads‘的实例,因为该类型的另一个具有相同键的实例已经被跟踪。在添加新实体时,对于大多数键类型,如果没有设置键(即,如果为键属性分配其类型的默认值),则将创建唯一的临时键值。如果要显式设置新实体的键值,请确保它们不会与现有实体或为其他新实体生成的临时值发生冲突。在附加现有实体时,请确保只将一个具有给定键值的实体实例附加到上下文。
以下是我的当前代码:
public class Ads