entity-framework-core

ASP.NET core POST request fail

旧巷老猫 提交于 2019-12-11 06:51:35
问题 I have a model: public class CoreGoal { [Key] public long CoreGoalId { get; set; } public string Title { get; set; } public string Effect { get; set; } public string Target_Audience { get; set; } public string Infrastructure { get; set; } public virtual ICollection<Benefit> Benefits { get; set; } public virtual ICollection<Step> Steps { get; set; } public virtual ICollection<Image> Images { get; set; } public virtual ICollection<SubGoal> SubGoals { get; set; } public CoreGoal() { } } And

How to use custom name convention with owned types?

非 Y 不嫁゛ 提交于 2019-12-11 06:49:38
问题 public class ProcessInitialization { public Guid CorrelationId { get; set; } public MyProcessContext ProcessContext { get; set; } } public class MyProcessContext { public int? ProcessId { get; set; } } Without using my convention I got SELECT `process`.`CorrelationId` FROM `ProcessInitialization` AS `process` WHERE `process`.`ProcessContext_ProcessId` = 8 My convention makes snake_case from PascalCase : public static void SetSimpleUnderscoreTableNameConvention(this ModelBuilder modelBuilder,

How do I enforce an either-or relationship between model properties, using EF Core?

非 Y 不嫁゛ 提交于 2019-12-11 06:25:45
问题 I'm using EF Core. My Customer entity has properties Address1 , Address2 , and AddressFull . Depending on which system sends me the data, I may receive Address1 and Address2 , or I may receive AddressFull . So I need: EITHER Address1 and Address2 required, and AddressFull not-required OR Address1 and Address2 not-required, and AddressFull required So I have: entityTypeBuilder.Property(p => p.Address1).IsRequired(false); entityTypeBuilder.Property(p => p.Address2).IsRequired(false);

Injecting RoleManager results in error

微笑、不失礼 提交于 2019-12-11 06:21:49
问题 First things first, my issue is similar to this SO link, but not the same I am going through the Identity sample from microsoft. I started it with only user authentication and it worked. I removed the DB because I want to use Database first. Now I am trying to incorporate Roles. My setup is like this for user (works without role) and role (didn't work): My DB entities are setup as such: public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<int>, int> { public

Override sql default value on insert using Entity Framework Core (7)

穿精又带淫゛_ 提交于 2019-12-11 06:14:46
问题 I have a table with a column [CreatedAtIsoUtc] that sets a Sql Server default value migrationBuilder.CreateTable( name: "CurrentAccountLedger", columns: table => new { Id = table.Column<Guid>(nullable: false, defaultValueSql: "newsequentialid()"), CreatedAtIsoUtc = table.Column<DateTime>(nullable: false, defaultValueSql: "GETUTCDATE()"), } }); In a raw sql server query, I can insert a record and overwrite the [CreatedAtIsoUtc] default value. In Entity Framework, I can't seem to overwrite this

Unable to cast object of type 'System.Double' to type 'System.Nullable`1[System.Single]'

≡放荡痞女 提交于 2019-12-11 06:13:38
问题 Why I'm getting the above error in this LINQ query - and how I can resolve it? System.Nullable<float> totalFreight = (from cust in db.Customers join ord in db.Orders on cust.ordID equals ord.OrdID select ord.Freight).Sum(); Note : Freight attribute/column in Orders entity/table is of type float? . I'm using EF Core 1.1 with VS2015 . UPDATE : I'm trying to follow this and this MSDN examples. UPDATE 2 : I isolated the issue as follows. Moreover, I verified, by hovering the mouse over ord

How to configure Pomelo.EntityFrameworkCore.MySql in XML configuration?

被刻印的时光 ゝ 提交于 2019-12-11 06:09:12
问题 I am trying to set up Entity Framework Core, with a Pomelo provider, in a .NET Framework (4.6.2) project. At runtime I get an error message The Entity Framework provider type 'Pomelo.EntityFrameworkCore.MySql, Pomelo.EntityFrameworkCore.MySql' registered in the application config file for the ADO.NET provider with invariant name 'MySqlConnector' could not be loaded. I am just guessing at the "invariantName" to use. According to Microsoft documentation, invariantName identifies the core ADO

ASP.Net Core saving base64 string

倾然丶 夕夏残阳落幕 提交于 2019-12-11 06:01:56
问题 I have a Image model: public class Image { [Key] public long ImagelId { get; set; } public string base64 { get; set; } } Which I use like following: public class CoreGoal { [Key] public long CoreGoalId { get; set; } [Required] public string Title { get; set; } public virtual ICollection<Image> Images { get; set; } public CoreGoal() { } } I am using MySql database. I intend to store possibly multiple images as base64 strings against each CoreGoal. Whenever I make a POST request with base64

Error while Add-Migration ef core 2 preview 1

独自空忆成欢 提交于 2019-12-11 05:55:53
问题 I'm trying to do a sample on ef core 2 but I'm getting the following when I try to add migrations PM> Add-Migration InitialCreate No parameterless constructor was found on 'ToDoContext'. Either add a parameterless constructor to 'ToDoContext' or add an implementation of 'IDbContextFactory<ToDoContext>' in the same assembly as 'ToDoContext'. I followed this tutorial https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db Here is my code. public class Startup { public void

SQL Server instance string connection in Linux Docker

≯℡__Kan透↙ 提交于 2019-12-11 05:51:48
问题 I'm publishing an application to docker image microsoft/dotnet:1.0.1-core that reference Sql Server instance in connection string: "Data Source=host\instance;Initial Catalog=database;User ID=user;Password=pass;" In Windows environment it work's as well, but using docker, the application cannot connect to the database. Changing the Data Source to use port instead of instance it works. "Data Source=host,port;Initial Catalog=database;User ID=user;Password=pass;" How can I connect, from docker,