entity-framework

Entity Framework Core: How to solve Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-06 08:44:28
问题 I'm using Entity Framework Core with Code First approach but recieve following error when updating the database: Introducing FOREIGN KEY constraint 'FK_AnEventUsers_Users_UserId' on table 'AnEventUsers' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors. My entities are these: public class AnEvent { public int AnEventId { get; set; } public DateTime

Using LINQ to query three entitites. - Include path expression must refer to a navigation property defined on the type

半城伤御伤魂 提交于 2020-07-06 04:37:06
问题 I am trying to get data from 3 entities. Exam, Objective and Objective detail. I want to be able to select this by exam name. Here is the code I am using: var result = await db.Exams .Include(e => e.Objectives) .Include(e => e.Objectives.SelectMany(o => o.ObjectiveDetails)) .Where(e => e.Name == name) .FirstOrDefaultAsync(); This is giving me an error message when I run it saying: exceptionMessage=The Include path expression must refer to a navigation property defined on the type. Use dotted

Using LINQ to query three entitites. - Include path expression must refer to a navigation property defined on the type

ぃ、小莉子 提交于 2020-07-06 04:29:06
问题 I am trying to get data from 3 entities. Exam, Objective and Objective detail. I want to be able to select this by exam name. Here is the code I am using: var result = await db.Exams .Include(e => e.Objectives) .Include(e => e.Objectives.SelectMany(o => o.ObjectiveDetails)) .Where(e => e.Name == name) .FirstOrDefaultAsync(); This is giving me an error message when I run it saying: exceptionMessage=The Include path expression must refer to a navigation property defined on the type. Use dotted

Can Entity Framework Core run non-query calls?

一世执手 提交于 2020-07-05 10:28:07
问题 Unfortunately my EF application has to call stored procedures I am unable to change. While this is not ideal I can normally get around it. However, I have a stored proc that does return anything. How does EF core deal with this? I know in previous versions you could run ExecuteNonQuery but I haven't been able to find anything similar in EF Core. I normally run my queries through a helper as such, where T is a class that maps to a return type EF can serialize to: context.Set<T>() .AsNoTracking

Can Entity Framework Core run non-query calls?

孤者浪人 提交于 2020-07-05 10:26:57
问题 Unfortunately my EF application has to call stored procedures I am unable to change. While this is not ideal I can normally get around it. However, I have a stored proc that does return anything. How does EF core deal with this? I know in previous versions you could run ExecuteNonQuery but I haven't been able to find anything similar in EF Core. I normally run my queries through a helper as such, where T is a class that maps to a return type EF can serialize to: context.Set<T>() .AsNoTracking

Auto increment non key value entity framework core 2.0

隐身守侯 提交于 2020-07-05 07:26:19
问题 I've got an object that has a key stored as a GUID as well as a friendlyID, like this: public class Job { [Key] public Guid Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int FriendlyId { get; set; } public string Description { get; set; } } However when I try to update description using my update method: public void Update(Job job, Job jobParam) { if (job == null) { throw new AppException("Job does not exist"); } //Update job properties job.Description =

Auto increment non key value entity framework core 2.0

二次信任 提交于 2020-07-05 07:25:24
问题 I've got an object that has a key stored as a GUID as well as a friendlyID, like this: public class Job { [Key] public Guid Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int FriendlyId { get; set; } public string Description { get; set; } } However when I try to update description using my update method: public void Update(Job job, Job jobParam) { if (job == null) { throw new AppException("Job does not exist"); } //Update job properties job.Description =

How do I add a foreign key to Identity user in EF Core?

女生的网名这么多〃 提交于 2020-07-05 03:18:26
问题 Let's say I have a Todo model with a corresponding Todo table ( DbSet<Todo> ) in an EF-generated database. The table will store a todo item per row. Each user (in an ASP.NET Core Identity + IdentityServer app) will be associated with multiple todo items (one-to-many, a user can have multiple todo items). The way I'd do it is to add a UserId foreign key to the Todo model that represents the user that owns the todo item . How would I do that with EF Core while utilizing the classes proved by

System.Linq.Expressions exception thrown when using FirstOrDefault in .Net Core 2.1

旧时模样 提交于 2020-07-05 02:12:57
问题 I am receiving ~300+ exceptions that are spammed in my server output labeled: Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll The query I am using is as follows: Account account = _accountContext.Account. Include(i => i.Currency). Include(i => i.Unlocks). Include(i => i.Settings). Include(i => i.Friends). FirstOrDefault(a => a.FacebookUserID == facebookUserID); Eventually the exceptions stop generating, it shows a large query in the output window, and everything

System.Linq.Expressions exception thrown when using FirstOrDefault in .Net Core 2.1

家住魔仙堡 提交于 2020-07-05 02:09:50
问题 I am receiving ~300+ exceptions that are spammed in my server output labeled: Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll The query I am using is as follows: Account account = _accountContext.Account. Include(i => i.Currency). Include(i => i.Unlocks). Include(i => i.Settings). Include(i => i.Friends). FirstOrDefault(a => a.FacebookUserID == facebookUserID); Eventually the exceptions stop generating, it shows a large query in the output window, and everything