entity-framework-6

EF 6 IsRequired() allowing empty strings

烈酒焚心 提交于 2019-12-04 00:08:39
In past projects with versions of EF5 and EF4, the IsRequired() fluent API method would thrown a DbEntityValidationException if the property was null or an empty string. In my current project utilizng EF6, The DBEntityValidationException is not thrown when the string property is empty. Entity: public class Application : BaseEntity { public string Name { get; set; } // navigation properties public IList<Role> Roles { get; set; } } Configuration: internal class ApplicationMapping : EntityTypeConfiguration<Application> { public ApplicationMapping() { // table name this.ToTable("Applications"); //

EntityFramework 6.1.3 does not support framework .NETPlatform,Version=v5.4 on visual studio 2015

一世执手 提交于 2019-12-03 23:31:48
Any idea why I receive the following error after Nuget installing Entity framework 6.1.3? Error notice: "The dependency EntityFramework 6.1.3 in project foo bar does not support framework .NETPlatform,Version=v5.4" Here's my global.json (edited out personal data) { "version": "1.0.0-*", "description": foo bar Class Library", "authors": [ "foo bar" ], "tags": [ "" ], "projectUrl": "", "licenseUrl": "", "frameworks": { "net451": { }, "dotnet5.4": { "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516", "System.Collections": "4.0.11-beta-23516", "System.Linq": "4.0.1-beta-23516", "System

Insert Record in Temporal Table using C# Entity Framework

∥☆過路亽.° 提交于 2019-12-03 22:42:26
I'm having issue in Insertion of data in Temporal table using C# Entity Framework The Table schema is CREATE TABLE People( PeopleID int PRIMARY KEY NOT NULL, Name varchar(50) Null, LastName varchar(100) NULL, NickName varchar(25), StartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL, EndTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL, PERIOD FOR SYSTEM_TIME (StartTime,EndTime) ) WITH (SYSTEM_VERSIONING = ON(HISTORY_TABLE = dbo.PeopleHistory)); I created an EDMX asusal and I tried to Insert a record using following C# Code using (var db = new DevDBEntities()) { People1 peo = new

FindAsync with non-primary key value

折月煮酒 提交于 2019-12-03 22:40:58
public class Foo { public int Id { get; set; } public int UserId { get; set; } } This appears to be the way to do this asynchronously: DatabaseContext db = new DatabaseContext(); Foo foo = await db.Foos.FindAsync(fooid); How does one asynchronously get all of the Foos for a specific user based on UserId's value? Assuming you are using Entity Framework 6.0 (prerelease): var userId = ...; var foos = await db.Foos.Where(x => x.UserId == userId).ToListAsync(); 来源: https://stackoverflow.com/questions/18964488/findasync-with-non-primary-key-value

DbSet<entity>.Load() function missing in EF 6.0

拈花ヽ惹草 提交于 2019-12-03 22:10:35
I am trying to access the DbSet<EntityClass>.Load() function to load the entities. This function no longer exists in EF 6.0; upon certain investigation I found that it is a part of the extension methods defined in the EF extension library. I get the reference NuGet Packages for EF 6.0 extended library but seems like it's no longer supported. I tried to do an alternative of that function by calling .ToList() , but this method upon processing returns me an inner exception: ({"The column name is not valid. [ Node name (if any) = Extent1,Column name = HasErrors ]"} ) I double checked the mapping

Entity Framework Poor COUNT Performance

▼魔方 西西 提交于 2019-12-03 21:34:09
问题 We are experiencing very poor performance using Entity Framework 5.0 with MySql Connector 6.6.6.0 for count based queries. Our data structure looks like: Table: Post =========== ID INT PRIMARY KEY MemberID INT NOT NULL SiteID INT NOT NULL Description VARCHAR(255) NOT NULL Image VARCHAR(255) NOT NULL CreatedDate DATETIME NULL And using entity framework with a linq query like the following: var count = entities.Post.Where(p => p.SiteID == 1 && p.CreatedDate != null).Count(); We get the

Concurrency exceptions in Entity Framework

拟墨画扇 提交于 2019-12-03 20:43:05
问题 When calling SaveChanges / SaveChangesAsync in Entity Framework (CF, C#), if a change conflict occurs (for example, the values has been updated since last read thingy), then which of these two exceptions DbUpdateConcurrencyException OR OptimisticConcurrencyException shall I catch? And what is the difference between them? 回答1: DbUpdateConcurrencyException is a specific exception thrown by DbContext , so this is the one to catch. This exception may be caused by an underlying

Adding Inner Join to DbScanExpression in Entity Framework Interceptor

删除回忆录丶 提交于 2019-12-03 17:13:49
问题 I'm trying to use an Entity Framework CommandTree interceptor to add a filter to every query via a DbContext. For the sake of simplicity, I have two tables, one called "User" with two columns ("UserId" and "EmailAddress") and another called "TenantUser" with two columns ("UserId" and "TenantId"). Each time there is a DbScan of the User table, I want to do an inner join against the TenantUser table and filter based on the TenantId column. There is a project called EntityFramework.Filters that

Code-first: Mapping entities to existing database tables

时光总嘲笑我的痴心妄想 提交于 2019-12-03 17:07:31
问题 I am using Entity Framework 6 code-first with an existing database, but having problems mapping my entities to the database tables. Normally, I would use database-first approach and have my entity and context code generated, but using the designer has become a huge pain. I have set Database.SetInitializer(null) as I do not want EF to change my schema. Database schema: Code-first: public class Project { public int ProjectId { get; set; } public string Name { get; set; } public string

Visual Studio 2015 RC Entity Framework 6.1.3 Migrations Error

孤者浪人 提交于 2019-12-03 16:25:10
问题 The pasted below error only occurs when the solution has more than one project that references the EntityFramework. When run the "Enable-Migrations" or "Add-Migration", I received the following error: New-Object : The value supplied is not valid, or the property is read-only. Change the value, and then try again. At D:\Projetos\Monitoramento\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:757 char:13 + $info = New-Object System.AppDomainSetup -Property @{ + ~~~~~~~~~~~~~~~~~~~~~~~~~