entity-framework

System.ObjectDisposedException when trying to receive the data from a List

旧城冷巷雨未停 提交于 2020-01-05 09:22:58
问题 Hello I am writing an ASP.Net MVC application and I have a special class dedicated for Database connection. In my HomeController I call the static methods of this special DB class, which return the needed data into objects. I use the Entity Framework in order to achieve this. However I get a strange exception when I try to use the List from my Controller. I believe that the problem is that I have a virtual inner collection that is disposed after the entity framework methods are done. I can

Will the Orberby for an Icollection<> be performed on the database level or application level

我的未来我决定 提交于 2020-01-05 09:21:59
问题 I am working on an asp.net mvc 3 web application , and i have the folloiwng model class inside my .tt folder:- public partial class Patient { public Patient() { this.Visits = new HashSet<Visit>(); } public int PatientID { get; set; } //code goes here... public virtual Gender Gender { get; set; } **public virtual ICollection<Visit> Visits { get; set; }** Then on the Controller class i wrote the following :- public PartialViewResult ShowOther(int id, int skip, int take ) { ViewBag.take = take;

How to filter by fields from navigation properties in Entity Framework?

烈酒焚心 提交于 2020-01-05 08:52:24
问题 I have classes like: public class ProductInCategory { public Guid Guid { get; set; } public long ProductID { get; set; } public long ProductCategoryID { get; set; } public virtual Product Product { get; set; } public virtual ProductCategory ProductCategory { get; set; } } public class Product { public virtual ICollection<ProductInCategory> ProductsInCategories { get; set; } // and other fields and navigation properties not important for this example } And now I want to execute query which

Check if navigational property is loaded

谁都会走 提交于 2020-01-05 08:42:10
问题 Is it possible to check if a navigational property has been loaded? When I try to access it I only get an ObjectDisposedException The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. public class Factory { // .. public virtual ICollection<Machine> Machines { get; set; } } // ... IList<Factory> set; using (MyContext context = new MyContext()) { set = context.Factories.ToList(); } ... later on // Is it possible to check if .Machines is

Check if navigational property is loaded

妖精的绣舞 提交于 2020-01-05 08:42:06
问题 Is it possible to check if a navigational property has been loaded? When I try to access it I only get an ObjectDisposedException The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. public class Factory { // .. public virtual ICollection<Machine> Machines { get; set; } } // ... IList<Factory> set; using (MyContext context = new MyContext()) { set = context.Factories.ToList(); } ... later on // Is it possible to check if .Machines is

Entity Framework Migration From Command Line

别来无恙 提交于 2020-01-05 08:37:35
问题 Is it possible doing some entity framework migration commands from a lightweight command line like visual studio cl? I can't access to my remote sql express server from local visual studio so I can't add-migration and update-database commands. So if there would be a cl, I could solve my problem. 回答1: There is a Migrate.exe tool which comes with EF which you can run through the command line. Documentation for it can be found at: http://msdn.microsoft.com/en-us/data/jj618307.aspx Used something

Linq OrderedQueryAble Error

喜你入骨 提交于 2020-01-05 08:20:09
问题 First Thing's First I have a class to manipulate some data through a linq variable: public class Result { public bool LongerThan10Seconds { get; set; } public int Id { get; set; } public DateTime CompletionTime { get; set; } } Then in a Separate class I'm using this to grab info from a linq var using (var data = new ProjectEntities()) { Result lastResult = null; List<Result> dataResults = new List<Result>(); foreach(var subResult in data.Status.Select(x => x.ID).Distinct().Select(Id => data

When declaring relationship is not necessary in Entity Framework 6?

喜欢而已 提交于 2020-01-05 08:08:10
问题 In EF6 we have two ways to declare relationship between two tables: Annotations Attributes Fluent API Today (by accident) I removed one relationship between two tables and everything kept working well. I was very surprised because there was no way EF would know how those two tables are connected. Tables look like that: [Table("item")] public class Item { public Item() { ItemNotes = new HashSet<ItemNote>(); } [Key] [Column("itemID", TypeName = "int")] [DatabaseGenerated(DatabaseGeneratedOption

Conditional Include not working with Entityt Framework 5

我是研究僧i 提交于 2020-01-05 08:06:31
问题 I'm trying to use the Conditional Include (explained here, but it's not retrieving the child information. Why? I think I've followed all the steps... I'm using WebApi controllers and Visual Studio 2012 I've alread checked and I have doorTypes assigned to each house. It's a many to many relationship. I have this: DoorType has this property public virtual ICollection<House> Houses{ get; set; } House has this property public virtual ICollection<Door> DoorTypes{ get; set; } And I'm querying this

Conditional Include not working with Entityt Framework 5

醉酒当歌 提交于 2020-01-05 08:06:27
问题 I'm trying to use the Conditional Include (explained here, but it's not retrieving the child information. Why? I think I've followed all the steps... I'm using WebApi controllers and Visual Studio 2012 I've alread checked and I have doorTypes assigned to each house. It's a many to many relationship. I have this: DoorType has this property public virtual ICollection<House> Houses{ get; set; } House has this property public virtual ICollection<Door> DoorTypes{ get; set; } And I'm querying this