entity-framework

Why does identity generator break unit of work in nHibernate? What about EF?

一曲冷凌霜 提交于 2020-01-15 05:40:10
问题 I understand and accept that the identity generator breaks the unit of work because it requires an insert prior when the transaction should actually commit, described in http://fabiomaulo.blogspot.com/2008/12/identity-never-ending-story.html. I'm aware of the alternatives and why they are better (in relation to the problem at hand, and in general). The question I have is why the implementation exists as it does, and whether or not these issues affect EF (sheer curiosity). The only real

Update entity with ViewModel and Entity Framework 6?

北城以北 提交于 2020-01-15 05:40:09
问题 I've been looking around and can't quite find the answer. I'm using a ViewModel in my Edit View so that I can have values for some dropdownlist. Now when I go to update my DB I'm not understanding how I can update my database record. I'm guessing I could create a new entity object, do a Find, and then update each property based on the ViewModel passed in from the Form but that sure seems like a lot of manual work. Here I'm using the VeiwModel in the Edit View. @model CPPCustomerCall

Adding object to database using table-per-type inheritance in Mvc 4

让人想犯罪 __ 提交于 2020-01-15 05:31:16
问题 I have a class Landlord that inherits from UserProfile using table-per-type inheritance. When a new user registers on the application, they enter some criteria and select the type of account they want, either Landlord or Tenant . Here's my AccountController/Register method: public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email, FirstName =

Surrogate Key vs Natural Key for EF

一世执手 提交于 2020-01-15 05:24:05
问题 My co-worker and I are trying to decide which is a better way to design the schema and keys for two database tables. One is a lookup-table that rarely changes. It has about 700 rows. The other table references the lookup-table. This table will have many thousand rows over time. In Design B, the lookup table has a primary key consisting of 3 varchars. The other table has a primary key consisting of the same 3 varchars with the addition of two date fields. In Design A, the 3 varchars are

EF Code First Foreign Key's

时间秒杀一切 提交于 2020-01-15 05:01:35
问题 I am working with the EF Code First library trying to work on an appointment scheduling app. The model's I have are going to be a Client, Appointment, and AppointmentType... Basically each Client can have a set of Appointments, and each Appointment can have a single AppointmentType... The code is as follows: public class Client { [ScaffoldColumn(false)] public int ClientID { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; }

How do I insert entities with a 1:n relationship in Azure App Service

你。 提交于 2020-01-15 05:00:30
问题 I need a 1:n relationship using the Azure App Service. I followed this tutorial for the entities. My client entities (same as tutorial, except I added a constructor): public abstract class Entity { // defines id, version, createdAt, updatedAt, deleted } public class Animal : Entity { public string Name { get; set; } } public class Zoo : Entity { public Zoo() { Animals = new List<Animal>(); } public string Name { get; set; } public List<Animal> Animals { get; set; } } My server entities (same

The instance of entity type Model cannot be tracked because another instance with the same key value for {'Id'} is already being tracked

╄→尐↘猪︶ㄣ 提交于 2020-01-15 04:14:47
问题 I have a problem, when will I do update in my database, I have this exception. The instance of entity type 'ExpenseReport' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values. tracked already This is my method to do an update. public

The instance of entity type Model cannot be tracked because another instance with the same key value for {'Id'} is already being tracked

时光毁灭记忆、已成空白 提交于 2020-01-15 04:14:47
问题 I have a problem, when will I do update in my database, I have this exception. The instance of entity type 'ExpenseReport' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values. tracked already This is my method to do an update. public

Loading instance of entity takes more than 1 second

倖福魔咒の 提交于 2020-01-15 03:43:06
问题 I ran into one interesting thing in EF. If we get child entity using base entity, loading entities takes more time. My model looks like this: public abstract class BaseDocument { public Guid Id { get; set; } public string Name { get; set; } } public abstract class ComplexDocument : BaseDocument { public string AuthorName { get; set; } } public abstract class SimpleDocument : BaseDocument { public int Level { get; set; } } public abstract class OfficeDocument : ComplexDocument { public string

How to use Clutch for debugging SQL statements executed by the Entity Framework?

核能气质少年 提交于 2020-01-15 03:27:16
问题 I am very new to the Entity Framework. Tried to save an object and it fails with the message error in saving entities which do not make foreign key properties available As something wrong happens when EF tries writing to the database, I wanted to see the actual query it is trying to execute. I am not yet using EF 6, so I can't use context.Database.Log. Some search told me that there is a library called Clutch Diagnostics which will help me. I installed it from NuGet and set it up as described