entity-framework-4.1

How to use Order By in this MSDN example

纵然是瞬间 提交于 2019-12-22 03:58:18
问题 I'm trying to figure out how to use this orderBy parameter. I am not sure what I am suppose to pass in. http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter !=

what is the best practice to set up DbContext in StructureMap for console app?

送分小仙女□ 提交于 2019-12-22 01:40:21
问题 I use StructureMap, EF 4.1/POCO. Console app supposes to run 2 consequent operations upon some set of data, lets say operation1 and operation2. I set DbContext up as an singleton. This causes problem in operation2 as operation1 left some trash in its DbContext that prevent operation2 works well. In the same time I can not set up DbContext as 'per call' coz operation1 uses 2 repositories sharing the same DbContext passing through their constructor. So ideally I need reinitialize/reset/cleanup

DbContext's ChangeTracker problem

时光总嘲笑我的痴心妄想 提交于 2019-12-22 01:37:06
问题 I have a codefirst EF-4.1 based program. The user gets a context and can modify some properties. When the user is done, I do a quick ChangeTracker.Entries().Any(e => e.State != EntityState.Unchanged); to determine if a SaveChanges() is required or not. If I do a 'SaveChanges()' call, the changes that have made are persisted to the database. This works for some properties, and doesn't work for others. Specifically it seems to work with simple types ( float s), and with collection hierarchies(

Lazy / Deferred loading of links not on time?

怎甘沉沦 提交于 2019-12-22 00:24:00
问题 Did someone experience the following? Validating objects with fields that refer to other Entities would throw you an error stating that the field wasn't present and that when you would debug the program and you would inspect the entities that the fields are populated. This has happened to me on two occasions now and it seems to be some problem with lazy loading, as if the lazy loading did not give the answer fast enough. We have this (simplified) model where class Survey { ... public bool

EF4.1 hangs for 120 seconds when using Microsoft.ApplicationServer.Caching.DataCacheFactory

北慕城南 提交于 2019-12-21 23:19:06
问题 I have a consistent, repeatable 120 second hang whenever the application calls this.cacheProvider.Add(new CacheItem(cacheKey, data, this.regionName), cachePolicy); at line 60 of the CachedDataSource.cs of the sample.. The .Add method is internal to Microsoft's DLL and I don't have code to it. Here are my parameters: cacheKey = "listofCompanies" data = // this is an EF 4.0 database first model class with 70 entries... result from IQueryable this.regionName = "companies" Reproducing the error:

How to add a column to a link table with code first

你说的曾经没有我的故事 提交于 2019-12-21 21:56:30
问题 I have a ResearchDatabase entity that has a many-to-many relationship with a Subject entity. i.e. a Research Database belongs in one or more Subject Categories, and a Subject Category contains one or more Research Databases. In my ResearchDatabaseConfiguration file I have the following mapping: HasMany(rd => rd.Subjects) .WithMany(s => s.ResearchDatabases) .Map(m => { m.MapLeftKey("DatabaseId"); m.MapRightKey("SubjectId"); m.ToTable("DatabaseSubjects"); }); OK, no problem. Works. Creates a

Entity Framework 4.1 - TPT Eager Loading - “The ResultType of the specified expression is not compatible with the required type”

你离开我真会死。 提交于 2019-12-21 20:51:13
问题 I have a model with TPT inheritance. Location ( abstract ) Street ( derived from Location) GoogleStreetView ( 1 Street -> 0..1 GoogleStreetView ) Each of the above has it's own table. All was working fine until i added the "GoogleStreetView" table (which is backed by a PK/FK to Street). When i try and do this: var street = _locationRepository .Find() .OfType<Street>() .Include(x => x.GoogleStreetView) .SingleOrDefault(x => x.LocationId == 1); I get the error: The ResultType of the specified

SQLite CreateDatabase not supported error

扶醉桌前 提交于 2019-12-21 20:40:47
问题 I'm using Entity Framework 4.2 CF with SQLite, but when i try to launch the application i got "CreateDatabase is not supported by the provider" error. This is my model mapping: protected override void OnModelCreating(DbModelBuilder modelBuilder) { #region NewsMapping modelBuilder.Entity<News>().ToTable("news"); modelBuilder.Entity<News>().HasKey(x => x.Id).Property(x => x.Id).HasColumnName("ID").HasColumnOrder(0); modelBuilder.Entity<News>().Property(x => x.Status).HasColumnName("STATUS");

Reload() not updating EF entity

前提是你 提交于 2019-12-21 20:15:42
问题 i like the .NET MVC practice of getting an instantiated class model passed to the controller which already has some of its properties filled in from posted form values. very handy. [HttpPost] public ActionResult DoTask(MyModel model) model arrives with its id and other properties set from the posted form data. however, suppose i want to save the model and then access additional properties that exist only in the database. i need to reload the model at this point. db.Entry(model).State =

Top per group: Take(1) works but FirstOrDefault() doesn't?

霸气de小男生 提交于 2019-12-21 09:19:36
问题 I'm using EF 4.3.1 ... just upgraded to 4.4 (problem remains) with database-first POCO entities generated by the EF 4.x DbContext Generator . I have the following database named 'Wiki' (SQL script to create tables and data is here): When a wiki article is edited, instead of its record being updated, the new revision is inserted as a new record with the revision counter incremented. In my database there is one author, "John Doe", which has two articles, "Article A" and "Article B", where