entity-framework

Polymorphism in Entity Framework

微笑、不失礼 提交于 2020-01-13 18:09:12
问题 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

EF 6 Code based migration exception: Microsoft.VisualStudio.Data.Tools.Package not serializable?

故事扮演 提交于 2020-01-13 18:09:05
问题 I have this configuration internal sealed class Configuration :DbMigrationsConfiguration<IAS.Models.ApplicationDbContext> { public Configuration() { AutomaticMigrationsEnabled = false; ContextKey = "IAS.Models.ApplicationDbContext"; } protected override void Seed( IAS.Models.ApplicationDbContext context ) { var baseDir = AppDomain.CurrentDomain.BaseDirectory; context.Database.ExecuteSqlCommand(File.ReadAllText(baseDir + "\\MyInsertScriptsql")); } } when running upate-dataabase i get the

DBContext Find with Includes - where lambda with Primary keys

萝らか妹 提交于 2020-01-13 17:10:19
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

DBContext Find with Includes - where lambda with Primary keys

泪湿孤枕 提交于 2020-01-13 17:09:56
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

DBContext Find with Includes - where lambda with Primary keys

纵然是瞬间 提交于 2020-01-13 17:09:30
问题 I am writing a generic repository to interface with EF using DBContext. I have a generic Get() method which receives a primary key value and returns the entity: public class DALRepository<DALEntity> : IDisposable, IGenericRepository<DALEntity> where DALEntity : class { private IDbSet<DALEntity> dbSet; private NWEntities context; public DALRepository() { context = new NWEntities(); context.Configuration.LazyLoadingEnabled = false; dbSet = context.Set<DALEntity>(); } Here's a simple get method

How to Deploy “SQL Server Express + EF” Application

梦想的初衷 提交于 2020-01-13 17:06:13
问题 It's my first time to Deploy an Application which uses SQL Server Express Database. I'm Using Entity Framework Model First to contact Database. and i created a Setup wizard with Install Shield to Install the App. These are Steps that I'v done to Install The Application in Destination Computer : Installing MS SQL Server Express (DEST) Installing The Program using Setup file (DEST) Detach Database from SQL server and Copy Related .mdf ,.ldf file to the Destination Computer. Attach database file

IQueryable does not contain definition for GetAwaiter

感情迁移 提交于 2020-01-13 16:23:31
问题 I'm using WebAPI in entity framework to create a new endpoint and I am having some issues. I'm trying to use a Linq Where statement to get my data, but I'm receiving the following error. 'IQueryable' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IQueryable' could be found (are you missing a using directive or an assembly reference?) Here is my code. [ResponseType(typeof(Vocab))] public async Task<IHttpActionResult>

Ado.Net Entity : Object doesn't display linked members (foreign keys)

谁说胖子不能爱 提交于 2020-01-13 15:53:32
问题 I have a simple databasescheme: User, Account. User has 1-to-many relationship with Account. I have generated a ado.net entity data model, and I can create users and accounts, and even link them together. In the database the account.user_id is correctly filled, so theoretically I should be able to acces User.Account.ToList() in C# through entity. However, When I try to acces User.Account.ToList() I get zero results. User user = db.User.First(U => U.id == 1); List<Account> accounts = user

linq to entity: linq query performance optimization

喜你入骨 提交于 2020-01-13 13:53:12
问题 i'm using EF 4.4.20627.0 with MySQL 5.6 , MySQL .net connector version 6.6.4 i have a method like this, which generated sql is very very slow (needs more than 1 min) private List<TNews> GetPagedNews(int pagenum, int pagesize, AdvSearcherArgs advcArgs, string keyword) { var dataSrc = _dbRawDataContext.TNews.Where(x => x.Id>0); if (!string.IsNullOrWhiteSpace(advcArgs.PMAC)) { dataSrc = dataSrc.Where(m => m.Pmac == advcArgs.PMAC); } if (!string.IsNullOrWhiteSpace(advcArgs.BegineDate)) { var

linq to entity: linq query performance optimization

旧街凉风 提交于 2020-01-13 13:52:54
问题 i'm using EF 4.4.20627.0 with MySQL 5.6 , MySQL .net connector version 6.6.4 i have a method like this, which generated sql is very very slow (needs more than 1 min) private List<TNews> GetPagedNews(int pagenum, int pagesize, AdvSearcherArgs advcArgs, string keyword) { var dataSrc = _dbRawDataContext.TNews.Where(x => x.Id>0); if (!string.IsNullOrWhiteSpace(advcArgs.PMAC)) { dataSrc = dataSrc.Where(m => m.Pmac == advcArgs.PMAC); } if (!string.IsNullOrWhiteSpace(advcArgs.BegineDate)) { var