entity-framework

Entity Framework: Generic compare type without Id?

早过忘川 提交于 2020-01-05 04:27:07
问题 Is there anyway to do a comparison between objects for equality generically without objects having an ID? I am trying to do a typical generic update, for which I have seen many examples of online, but they all usually look something like this: public void Update(TClass entity) { TClass oldEntity = _context.Set<TClass>().Find(entity.Id); foreach (var prop in typeof(TClass).GetProperties()) { prop.SetValue(oldEntity, prop.GetValue(entity, null), null); } } or something similar.The problem with

Why to use fluentmigrator?

青春壹個敷衍的年華 提交于 2020-01-05 04:11:11
问题 When and why to use FluentMigrator as Entity Framework does the same job. If I have code- database then structures are already there and EF already provides classes to manipulate database. I am not clear why and when(in which cases) to use fluentmigrator? Thanks 回答1: Not everybody uses Entity Framework. I don't use it in my current project for example. In this scenario FluentMigrator is very useful for managing the database changes for each release. 回答2: EntityFramework kind of gives you both

UserManager.Update(user) method isn't thread safe

可紊 提交于 2020-01-05 04:05:14
问题 I'm trying to update a user with UserManager in a controller. Just before I update the user, a call to an external service fires a webhook that tries to update the same user, also using UserManager. But that's a different request and a different part of the application (the "webhook controller"). Here's the exception I got while debugging in the controller: System.Data.Entity.Core.EntityException. "An error occurred while starting a transaction on the provider connection. See the inner

Entity Framework Case Sensitive Query

橙三吉。 提交于 2020-01-05 03:49:10
问题 I have a table that named Post which has a column named key : Id | Key | Title -------------------- 1 | WM | First -------------------- 2 | wm | Second As you can see the first key value of a Post is WM (Uppercase) and the second key value is wm (lowercase). When I execute the query with following code: var post = await _posts.Where(o => o.Key == key).Select(o => new { id = o.Id, title = o.Title }).SingleOrDefaultAsync(); I pass the key with a value (wm and WM) but get one result. The second

How to generate code first migration script from a specific migration?

六月ゝ 毕业季﹏ 提交于 2020-01-05 03:36:12
问题 I have a production and a development database. Now I want to generate a sql script based on a specific migration. When I enter the line to generate the script I get this error: '201608121243147_AutomaticMigration' is not a valid migration. Explicit migrations must be used for both source and target when scripting the upgrade between them. The command I use is as follows: Update-Database -Script -SourceMigration:201608121243147_AutomaticMigration -TargetMigration:201608281101542

Delete related elements in 1:N relation and not only inserts null in the foreign key

白昼怎懂夜的黑 提交于 2020-01-05 03:34:52
问题 I have the following class public class ObjectA{ private List<ObjectB> list; } ObjectA and ObjectB are in 1:N relation. I want to delete some of ObjectB instances and I use: while (objectA.list.Any()) objectA.list.Remove(objectA.list.First()); List is of the relation table - List<ObjectAobjectB> In the Database I have defined therelation as a nullable foreign key otherwise I get The operation failed: The relationship could not be changed because one or more of the foreign-key properties is

Ignore a specific column in Entity Framework? [duplicate]

人盡茶涼 提交于 2020-01-05 03:33:29
问题 This question already has answers here : Entity Framework: Ignore Columns (6 answers) Closed 6 years ago . I have auto generated model from a database in Entity Framework version 4.1.10331.0. I want to ignore a column from an entity without using the Fluent Api and without changing the ObjectContext into DbContext (and of course without deleting the column from the SQL table) and without marking the property generated in the model with the attribute NotMapped , because whenever I update my

edmx no longer opens in designer after uninstalling Entity Framework Power tools

放肆的年华 提交于 2020-01-04 18:15:05
问题 I am using vs 2013 update 4 I uninstalled Entity Framework Power tools and now when I open my edmx it only opens as xml I have looked at projects that use Entity Framework 6.1 and 6.2 beta, and both have the problem. In addition if I right click the edmx and select Run Custom Tool, I get an error Canot find custom tool 'EntityModelCodeGenerator' on this system. I have since reinstalled Power Tools but the problem remains I have run Visual Studio Repair I have removed and then re-added Entity

Mocking Entity Framework 6 ObjectResult with Moq

不打扰是莪最后的温柔 提交于 2020-01-04 18:14:40
问题 How can I mock the Entity Framework 6 ObjectResult with Moq so that I can unit test my code that relies on an EF database connection? Having read numerous questions and answers along these lines, and gleaned many nuggets from what I've read, I've implemented what I feel is a reasonably elegant solution and felt that I should share it, since the community here helped me get there. Thus, I'll proceed to answer this question, and potentially open myself up to some mockery (pun intended): 回答1:

edmx no longer opens in designer after uninstalling Entity Framework Power tools

夙愿已清 提交于 2020-01-04 18:14:10
问题 I am using vs 2013 update 4 I uninstalled Entity Framework Power tools and now when I open my edmx it only opens as xml I have looked at projects that use Entity Framework 6.1 and 6.2 beta, and both have the problem. In addition if I right click the edmx and select Run Custom Tool, I get an error Canot find custom tool 'EntityModelCodeGenerator' on this system. I have since reinstalled Power Tools but the problem remains I have run Visual Studio Repair I have removed and then re-added Entity