entity-framework

Entity Framework 5 complex type and unknown column in field list error

谁说我不能喝 提交于 2020-01-14 01:57:11
问题 Bear with me as I'm new to C# and programming in general. I'm trying to define a complex type that is in the same table as the principle class. Basically, it's the good old User and Address example. public class Customer { [Key] public int customerId { get; set; } //some attributes public string street { get; set; } public string city { get; set; } public string province { get; set; } public string country { get; set; } public string postal { get; set; } } So I try to slice off the address

A relational store has been configured without specifying either the DbConnection or connection string to use

不想你离开。 提交于 2020-01-13 19:44:34
问题 I using asp.net vnext and ef7 when i want adding user i getting this error: A relational store has been configured without specifying either the DbConnection or connection string to use. What is this? Consider my app start: using DomainModels; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Routing; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Presentation.DataAccessLayer.Context; using Microsoft

System.Data.Entity.Infrastructure.DbUpdateConcurrencyException. Store update, insert, or delete statement affected an unexpected number of rows (0)

前提是你 提交于 2020-01-13 19:42:29
问题 Models These are model classes and I am using Entity Framework. I am using these models to implement cascaded drop down list. public class League { public int Id { get; set; } public string League1 { get; set; } public string Icon { get; set; } public virtual ICollection<LeagueDivision> LeagueDivisions { get; set; } } public class LeagueDivision { public int Id { get; set; } public Nullable<int> LeagueId { get; set; } public string Name { get; set; } public string Icon { get; set; } public

EF LINQ ToList is very slow

空扰寡人 提交于 2020-01-13 19:32:10
问题 I am using ASP NET MVC 4.5 and EF6 , code first migrations. I have this code, which takes about 6 seconds. var filtered = _repository.Requests.Where(r => some conditions); // this is fast, conditions match only 8 items var list = filtered.ToList(); // this takes 6 seconds, has 8 items inside I thought that this is because of relations, it must build them inside memory, but that is not the case, because even when I return 0 fields, it is still as slow . var filtered = _repository.Requests

should EF dbContext be created on every transaction

*爱你&永不变心* 提交于 2020-01-13 19:22:51
问题 I'm trying to figure out the best way to manage the DbContext. I've seen code samples that don't dispose and I've seen people say that that is a bad idea. Is it appropriate for me to do something like below? Also, should I put every transaction, including reads, in a new DbContext? This might be another question, but is the part about the EntityState necessary? public abstract class GenericRepository<T> where T : EntityData { protected MyDbContext Context { get { return new MyDbContext(); } }

Why the anonymous type instance cannot accept null values returned by the entity framework query?

这一生的挚爱 提交于 2020-01-13 19:20:07
问题 When I try to run the following Entity Framework query: var l = (from s in db.Samples let action = db.Actions.Where(x => s.SampleID == x.SampleID && x.ActionTypeID == 1).FirstOrDefault() where s.SampleID == sampleID select new { SampleID = s.SampleID, SampleDate = action.ActionDate, }).ToList(); I get following exception: The cast to value type 'DateTime' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type. The

Is there a better/cleaner way to find Independent Association changes (adds/removes) than this?

女生的网名这么多〃 提交于 2020-01-13 19:10:40
问题 I found this answer which (unless I'm missing something) gives a good solution to catch all changes made to all independent associations in a DbContext. I am trying to adapt that solution to something more specific, to create a function that can find the changes for a particular navigation property on a particular entity. The goal is for the user of this function to not have to worry about any of the internals of EntityFramework, and to only be concerned with his POCO models. This is what I

Asp.net core - no such table: AspNetUsers

喜欢而已 提交于 2020-01-13 19:03:31
问题 So im trying to implment user login for my a asp.net core application. Im following the microsoft tutorial here. I have two contexts, one called SchoolContext for saving all the school related models, and another context called ApplicationDbContext for the Account models. This is all being saved to a sqlite database. Everything works fine, up until I try to register a user to my context. When I try to register a user i get, cant find AspNetUsers table error. If I look in the database I don’t

How to use DbContext in T4 template?

五迷三道 提交于 2020-01-13 18:54:11
问题 I want to generate some code with a T4 Template using EntityFramework. I created a T4 Template in the same Assembly as my currently working EF6 DbContext: <#@ template language="C#" hostspecific="true" debug="True" #> <#@ assembly name="$(SolutionDir)\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #> <#@ assembly name="$(TargetPath)" #> <#@ import namespace="Conwell.Administration.Data.Entities" #> <# using (var db = new KassenautomatEntities()) { #> //Hello World <# } #> When

Polymorphism in Entity Framework

倖福魔咒の 提交于 2020-01-13 18:11:08
问题 The concrete classes ( BankAccount and CreditCard ) are not visible on controller. I'm stuck with this issue. I'm using the example from this site: http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx The view The CreateUser : If the CreditCard was selected it should be associated to the User class. The diagram The code UserController : [HttpPost] public ActionResult Create(User user)//The Watch