entity-framework-6

How to get original Entity from ChangeTracker

夙愿已清 提交于 2019-12-02 23:42:22
Is there a way to get the original Entity itself from the ChangeTracker (rather than just the original values)? If the State is Modified , then I suppose I could do this: // Get the DbEntityEntry from the DbContext.ChangeTracker... // Store the current values var currentValues = entry.CurrentValues.Clone(); // Set to the original values entry.CurrentValues.SetValues(entry.OriginalValues.Clone()); // Now we have the original entity Foo entity = (Foo)entry.Entity; // Do something with it... // Restore the current values entry.CurrentValues.SetValues(currentValues); But this doesn't seem very

MVC 5 - two separate models on a page, how do I attach one to a form so I can submit it?

烈酒焚心 提交于 2019-12-02 23:10:03
问题 TL;DR: How do I handle form data that is being submitted with nonstandard names for the data? The stats: MVC 5 ASP.NET 4.5.2 I am bringing in two different models: public async Task<ActionResult> Index() { var prospectingId = new Guid(User.GetClaimValue("CWD-Prospect")); var cycleId = new Guid(User.GetClaimValue("CWD-Cycle")); var viewModel = new OnboardingViewModel(); viewModel.Prospecting = await db.Prospecting.FindAsync(prospectingId); viewModel.Cycle = await db.Cycle.FindAsync(cycleId);

Entity Framework: The provider did not return a providermanifest instance

十年热恋 提交于 2019-12-02 22:33:42
Entity Framework 6.0.1 my App.config: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> <entityFramework> <defaultConnectionFactory type=

How to get id from entity for Auditlog in Entity Framework 6

你离开我真会死。 提交于 2019-12-02 22:26:27
I know it's several similar posts out there, but I cannot find any with a solution to this issue. I want to add a (sort of) AudioLog when adding, changing or deleting entities (soft-delete) in Entity Framework 6. I've overridden the SaveChanges and because I only want to add log entries for EntityStates Added, Modified or Deleted, I fetch the list before I call SaveChanges the first time. The problem is, because I need to log what operation has been executed, I need to inspect the EntityState of the entities. But after SaveChanges is called, the EntityState is Unchanged for all entries. public

ASP.NET MVC5 - Keeping Users in Oracle Database

被刻印的时光 ゝ 提交于 2019-12-02 21:05:56
Once creating a ASP.NET MVC5 project (with target framework is .NET 4.5.1 and the authentication type is Individual User Account ), so what is the most elegant way to configure the project so that it keeps the user, claims, roles etc. in an Oracle 12c database? I mean, how can I keep the authorization/authentication data in Oracle without deforming the automatically-generated MVC5 project structure. I guess changing the <defaultConnection> tag is not enough and there should be another Oracle implementation to replace Microsoft.AspNet.Identity.EntityFramework . It would be very helpful to

DropCreateDatabaseIfModelChanges EF6 results in System.InvalidOperationException: The model backing the context has changed

ぃ、小莉子 提交于 2019-12-02 20:48:02
After migrating to Entity Framework 6 I get an error when executing unit tests on the build server. I'm using the DropCreateDatabaseIfModelChanges initializer. When I change it to MigrateDatabaseToLatestVersion everything works, but I want to stick with the former initializer. The error I'm getting is: System.InvalidOperationException: System.InvalidOperationException: The model backing the 'AppContext' context has changed since the database was created. Consider using Code First Migrations to update the database ( http://go.microsoft.com/fwlink/?LinkId=238269 ).. Which is correct, it changed,

Unable To populate view or view model Updaed

只谈情不闲聊 提交于 2019-12-02 20:06:52
问题 Hi I am following up on this question here and working through a proof of concept for a SPA using our Company database data from a series of examples / articles Using Web API 2 with Entity Framework 6 Unfortunately, when I run the project I get this return This feels like a failure to retrieve the data from the SQL Database (SQL Server 2008R2). However I am getting no error message, which I though I would, I know the data view is there as I have checked in SQL Management studio and in Server

extend Where for IQueryable

旧时模样 提交于 2019-12-02 19:04:59
问题 I need to extend the Where method for IQueryable to something like this: .WhereEx("SomeProperty", "==", "value") I dont know if this is even possible, but i found this in SO : Unable to sort with property name in LINQ OrderBy I tried this answer and it seems quite interesting (Ziad's answer): using System.Linq; using System.Linq.Expressions; using System; namespace SomeNameSpace { public static class SomeExtensionClass { public static IQueryable<T> OrderByField<T>(this IQueryable<T> q, string

Entity Framework edmx click on diagram very slow

こ雲淡風輕ζ 提交于 2019-12-02 18:13:50
Background first: I have a database-first EF6 model in Visual Studio 2015 (latest nuget 6.1.3 pointing to a local SQL Server 2014 SP1 Express database) on a Windows 10 Pro laptop. After I upgraded from Windows 8.1 and Visual Studio 2013. I also upgraded the model from EF5 about 6 months ago as well, but I don't think this is relevant, as I've also tried rebuilding from scratch. The model: set of about 100 tables, 50 views and 250 associations. The problem is every time I want to make changes to my model, any kind of click (left or right) on the .edmx diagram causes Visual Studio to become

Entity Framework InverseProperty annotation usage

末鹿安然 提交于 2019-12-02 18:11:47
问题 if I have the following models, am I using the InverseProperty correctly? class Person { public int PersonID {get;set;} [InverseProperty("Person")] public List<Hobbies> Sports {get;set;} [InverseProperty("Person")] public List<Hobbies> Art {get;set;} [InverseProperty("Person")] public List<Hobbies> Reading {get;set;} } abstract class Hobbies { public int HobbiesID {get;set;} public string HobbyName {get;set;} public int HobbyRating {get;set;} public int PersonID {get;set;} public Person