entity-framework

How to group records and retrieve only first group with top N records

耗尽温柔 提交于 2021-01-27 08:20:37
问题 I have the following record set ID BatchID ClientName CreatedDateTime ----------- -------------- --------------- ----------------------- 1 NULL B 2018-02-16 19:07:46.320 2 NULL B 2018-02-16 19:07:46.320 3 NULL B 2018-02-16 19:07:46.597 4 NULL B 2018-02-16 19:07:46.597 5 NULL B 2018-02-16 19:10:10.260 6 NULL B 2018-02-16 19:10:10.260 7 NULL B 2018-02-16 19:21:34.303 8 NULL B 2018-02-16 19:21:34.303 9 NULL B 2018-02-16 19:21:44.780 10 NULL B 2018-02-16 19:21:44.780 11 NULL A 2018-02-16 19:24:35

Load can only be called when the EntityCollection or EntityReference does not contain objects

江枫思渺然 提交于 2021-01-27 08:17:14
问题 As Title showed, When I use lazyload of Entity Framework 4.1 which turned tracking off I got the error. Complete exception message: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects Does anyone knows why? 回答1: Set the Configuration.ProxyCreationEnabled field of your DbContext to false : using (var dbContext = MyDbContext()) { dbContext.Configuration.ProxyCreationEnabled = false; return

Load can only be called when the EntityCollection or EntityReference does not contain objects

陌路散爱 提交于 2021-01-27 08:17:10
问题 As Title showed, When I use lazyload of Entity Framework 4.1 which turned tracking off I got the error. Complete exception message: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects Does anyone knows why? 回答1: Set the Configuration.ProxyCreationEnabled field of your DbContext to false : using (var dbContext = MyDbContext()) { dbContext.Configuration.ProxyCreationEnabled = false; return

EF Core - circular reference and serializing to json

岁酱吖の 提交于 2021-01-27 07:35:14
问题 Example of entities: public class HistoryWorkoutExercise : EntityMaximum { /// <summary> /// Gets or sets the Weight. /// </summary> public decimal? Weight { get; set; } /// <summary> /// Gets or sets the Speed. /// </summary> public decimal? Speed { get; set; } /// <summary> /// Gets or sets the Time. /// </summary> public decimal? Time { get; set; } public int NumberOfRepetitions { get; set; } public int NumberOfCompletedRepetitions { get; set; } public int ExerciseId { get; set; } public

EF Core - circular reference and serializing to json

旧城冷巷雨未停 提交于 2021-01-27 07:34:56
问题 Example of entities: public class HistoryWorkoutExercise : EntityMaximum { /// <summary> /// Gets or sets the Weight. /// </summary> public decimal? Weight { get; set; } /// <summary> /// Gets or sets the Speed. /// </summary> public decimal? Speed { get; set; } /// <summary> /// Gets or sets the Time. /// </summary> public decimal? Time { get; set; } public int NumberOfRepetitions { get; set; } public int NumberOfCompletedRepetitions { get; set; } public int ExerciseId { get; set; } public

EF Core “Invalid column name 'Discriminator'” error with inheritance

笑着哭i 提交于 2021-01-27 06:44:08
问题 I have the following entities: public abstract class Freezer { public int FreezerId { get; set; } public string Name { get; set; } public int FreezerTypeId { get; set; } public int Capacity { get; set; } } public class FoodFreezer : Freezer { public List<FoodItem> Foods { get; set; } } public class ChemicalFreezer : Freezer { public List<ChemicalItem> Chemicals { get; set; } } As you can see the derived Freezer classes do not contain any data that would be stored in the database; they only

EF Core “Invalid column name 'Discriminator'” error with inheritance

丶灬走出姿态 提交于 2021-01-27 06:41:53
问题 I have the following entities: public abstract class Freezer { public int FreezerId { get; set; } public string Name { get; set; } public int FreezerTypeId { get; set; } public int Capacity { get; set; } } public class FoodFreezer : Freezer { public List<FoodItem> Foods { get; set; } } public class ChemicalFreezer : Freezer { public List<ChemicalItem> Chemicals { get; set; } } As you can see the derived Freezer classes do not contain any data that would be stored in the database; they only

Handling MySQL Zero Date with EF Core

可紊 提交于 2021-01-27 06:36:26
问题 Background: I have 200+ legacy VB6 apps which I am converting to C#, using EntityFramework Core as our ORM. Unfortunately a lot of the apps utilize MySQL's zero date (0000-00-00) . So I need to cater for this and be able to store a zero date in some way. Changing the fundamental way this works in the 200+ apps is not currently an option. Setup: I can define an entity property which represents the field definition in MySQL eg: public DateTime ExpiryDate { get; set; } ... entity.Property(e => e

.NET TransactionScope and MSDTC

时光总嘲笑我的痴心妄想 提交于 2021-01-27 06:22:46
问题 In my code there are transactions to handle: using (var scope = new TransactionScope()) { repo1.SaveSomething(); repo2.SaveAnythingElse(); scope.Complete(); } Inside repo1 and repo2 functions create their own db context with using, and dispose them, the transactions worked like a charm. Now I add another code like this, and it begins to drop an exception: The underlying provider failed on Open. (EntityFramework) Network access for Distributed Transaction Manager (MSDTC) has been disabled.

The model backing the 'POSContext' context has changed since the database was created

ぐ巨炮叔叔 提交于 2021-01-27 06:16:06
问题 I am developing winform application using entityframework in visual studio 2012 with database first approach. Suddenly I am facing the following error:- The model backing the 'POSContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269). Can any please immediately help me to resolve this issue. I shall be very thankful for timely help. Thanks. 回答1: make sure that you don't have a