entity-framework-6

Entity Framework using IdentityDbContext with Code First Automatic Migrations table location and schema?

北城余情 提交于 2019-12-07 01:55:19
问题 I am trying to setup automatic migration updates using the IdentityDbContext class and propagating changes to the actual DbContext for the entire database. Before I get into the code, on my implementation of the IdentityDbContext with automatic migrations I get this error: Automatic migrations that affect the location of the migrations history system table (such as default schema changes) are not supported. Please use code-based migrations for operations that affect the location of the

Make Entity Framework use Contains instead of Like and explain 'ESCAPE ~'

醉酒当歌 提交于 2019-12-07 01:07:59
问题 I have a line of LINQ that im using in EF which is basically doing myTable.Where(c => c.Contains('mystring')); This is the generated code: SELECT TOP (300) [Extent1].[ID] AS [ID], [Extent1].[FKFishEntityID] AS [FKFishEntityID], [Extent1].[Fish] AS [Fish], [Extent1].[FishText] AS [FishText], [Extent1].[FishType] AS [FishType] FROM [dbo].[Fish] AS [Extent1] WHERE [Extent1].[FishText] LIKE @p__linq__0 ESCAPE '~' My two questions are: How do I make it use CONTAINS(...) instead of LIKE? It seems

ASP.NET-Identity limit UserName length

南楼画角 提交于 2019-12-07 01:06:05
问题 How can I limit the UserName field in the table AspNetUsers ? Neither this: public class ApplicationUser : IdentityUser { [Required, MaxLength(15)] public string UserName { get; set; } } or this: modelBuilder.Entity<ApplicationUser>().Property(x => x.UserName).HasMaxLength(15); works. I need this because setting an Index on an nvarchar(max) gives me this error msg: Column 'UserName' in table 'dbo.AspNetUsers' is of a type that is invalid for use as a key column in an index. To be verbose, I

EF 6 - Cascade Delete on one to many without backreference

一个人想着一个人 提交于 2019-12-07 00:13:22
问题 I have something like this: public class Gadget { public int Id { get; set; } public string Name { get; set;} public int SuperHeroId { get; set; } } public class SuperHero { public int Id { get; set; } public virtual ICollection<Gadget> Gadgets { get; set; } } Notice that while a Gadget is "owned" by a Superhero (and therefore there's an FK in the database), my domain model does not have a hard reference in that direction. When I delete a superhero I would like to also delete all their

Entity Framework References go missing between debug and release build

吃可爱长大的小学妹 提交于 2019-12-06 23:04:34
问题 There must be something that I don't understand in the difference between debug builds and release builds and its use of references. I'm using Entity Framework 6 to connect to a database that has previously been set up. I am able to successfully build and run the project while it is in Debug mode. If I change it to release mode I instantly get build errors indicating that the namespaces and types that were just there can no longer be found. I checked and as far as I can tell they both target

Entity Framework lazy loading with AsNoTracking()

半城伤御伤魂 提交于 2019-12-06 21:39:40
问题 We are currently using lazy loading for Entity Framework and running into out of memory exception . The reason why we're running into this exception is because the Linq query loads a lot of data and at latter stages it's using lazy loading to load navigation properties. But because we don't use NoTrackingChanges Entity Framework cache builds up really quickly which results in out of memory error. My understanding with EF is the we should always use NoTrackingChanges on query unless you want

Has EF6+ / 7 added any ways that I can add update child tables?

元气小坏坏 提交于 2019-12-06 20:29:29
I have two tables: public AdminTest() { this.AdminTestQuestions = new List<AdminTestQuestion>(); } public int AdminTestId { get; set; } public string Title { get; set; } public virtual ICollection<AdminTestQuestion> AdminTestQuestions { get; set; } } public partial class AdminTestQuestion { public int AdminTestQuestionId { get; set; } public int AdminTestId { get; set; } public System.Guid QuestionUId { get; set; } public virtual AdminTest AdminTest { get; set; } } I am using the following EF6 code to add a new adminTest (with its adminTestQuestions) to the database: public async Task

Entity Framework 6 Update Graph

若如初见. 提交于 2019-12-06 19:04:40
问题 What is the correct way to save a graph of objects whose state you don't know? By state I mean whether they are new or existing database entries that are being updated. For instance, if I have: public class Person { public int Id { get; set; } public int Name { get; set; } public virtual ICollection<Automobile> Automobiles { get; set; } } public class Automobile { public int Id { get; set; } public int Name { get; set; } public short Seats { get; set; } public virtual ICollection

Entity Framework 6 Create() vs new

随声附和 提交于 2019-12-06 17:37:43
问题 What is the difference between adding an entity in these two ways? MyEntity me = new MyEntity(); entities.myentities.Add(me); vs MyEntity me = entities.myentities.Create(); Do I still need to add "me" in the second example? If so, is there some sort of advantage, one way or the other? Many thanks! 回答1: MyEntity me = new MyEntity(); will create a new instance of MyEntity MyEntity me = entities.myentities.Create(); will create a proxy wrapped instance of MyEntity (assuming your context is

Managed Oracle Client with Oracle Advanced Security Options

我只是一个虾纸丫 提交于 2019-12-06 16:46:48
On October 14th, Oracle release the latest version of their Oracle Managed Client which was described to support Network Data Encryption. http://www.oracle.com/technetwork/topics/dotnet/tech-info/odac12cr4ds-2704217.pdf https://www.nuget.org/packages/Oracle.ManagedDataAccess/ Although for some reason after trying multiple configuration, we still weren't able to get it to work. We keep getting the infamous ORA-12570: Network Session: Unexpected packet read error exception wrapped in The provider did not return a ProviderManifestToken string . The error in the alert log is the following TNS