ef-core-2.1

EF Core tools version update 2.1.1

烂漫一生 提交于 2019-12-01 02:29:30
If I run dotnet ef add testmigration I get this warning: The EF Core tools version '2.1.0-rtm-30799' is older than that of the runtime '2.1.1-rtm-30846'. Update the tools for the latest features and bug fixes. So I checked my csproj file: <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" /> <

EF Core tools version update 2.1.1

北城以北 提交于 2019-11-30 22:57:25
问题 If I run dotnet ef add testmigration I get this warning: The EF Core tools version '2.1.0-rtm-30799' is older than that of the runtime '2.1.1-rtm-30846'. Update the tools for the latest features and bug fixes. So I checked my csproj file: <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2

Getting “attempt was made to lazy-load navigation property on detached entity” despite eager fetch

不羁的心 提交于 2019-11-30 20:26:25
I'm using Entity Framework Core 2.1.2 with lazy loading enabled and am performing a query using AsNoTracking. I'm using Include to bring in my navigation property (a collection). If all my entities have at least one child in their collection then it all works fine. However, if any of my entities have no children then I get an error: System.InvalidOperationException: Error generated for warning 'Microsoft.EntityFrameworkCore.Infrastructure.DetachedLazyLoadingWarning: An attempt was made to lazy-load navigation property 'Children' on detached entity of type 'ParentProxy'. Lazy-loading is not

EF Core to Mysql table binding

こ雲淡風輕ζ 提交于 2019-11-28 14:44:33
I have the following table in MySQL When I run the following code in some middleware var apiKeys = _appContext.apikey.ToList(); I get this error System.InvalidOperationException: No coercion operator is defined between types 'System.Int16' and 'System.Boolean'. This is my ApiKey class public class ApiKey { public string apikeyid { get; set; } public string uid { get; set; } public string apikey { get; set; } public bool isactive { get; set;} public bool ispaid { get; set; } public bool ismod { get; set; } public bool isadmin { get; set; } } I had this working with a Postgresql db and just

Populate Created and LastModified automagically in EF Core

岁酱吖の 提交于 2019-11-28 10:34:18
Looking forward to build a framework, (No repository pattern to working with DbSets directly) to autopopulate Created and last modified automatically, rather than spitting out these codes through out code base. Could you point me out in right direction how to achieve it. In past I tried populating these in constructors, however that seems like a nasty code and every time we pull up somting from database EF change tracking will mark the entity as modified. .ctor() { Created = DateTime.Now; LastModified = DateTime.Now; } public interface IHasCreationLastModified { DateTime Created { get; set; }

Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

自古美人都是妖i 提交于 2019-11-27 03:22:22
Does any one know how I can specify the Default value for a DateTime property using the System.ComponentModel DefaultValue Attribute? for example I try this: [DefaultValue(typeof(DateTime),DateTime.Now.ToString("yyyy-MM-dd"))] public DateTime DateCreated { get; set; } And it expects the value to be a constant expression. This is in the context of using with ASP.NET Dynamic Data. I do not want to scaffold the DateCreated column but simply supply the DateTime.Now if it is not present. I am using the Entity Framework as my Data Layer Cheers, Andrew You cannot do this with an attribute because

Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

匆匆过客 提交于 2019-11-26 10:29:57
问题 Does any one know how I can specify the Default value for a DateTime property using the System.ComponentModel DefaultValue Attribute? for example I try this: [DefaultValue(typeof(DateTime),DateTime.Now.ToString(\"yyyy-MM-dd\"))] public DateTime DateCreated { get; set; } And it expects the value to be a constant expression. This is in the context of using with ASP.NET Dynamic Data. I do not want to scaffold the DateCreated column but simply supply the DateTime.Now if it is not present. I am