entity-framework

NHibernate equivalent of Entity Framework “Future Queries”

99封情书 提交于 2020-01-15 10:18:05
问题 There is an extension to Entity Framework called Future Queries that allows queries to be batched up and processed at the same time. For example, from their docs: // build up queries var q1 = db.Users .Where(t => t.EmailAddress == "one@test.com") .Future(); var q2 = db.Tasks .Where(t => t.Summary == "Test") .Future(); // this triggers the loading of all the future queries var users = q1.ToList(); Is there any equivalent in NHibernate, or an extension that might give this type of functionality

Save LINQ Query As Variable To Call Another LINQ Query

痴心易碎 提交于 2020-01-15 10:14:55
问题 I have a var type storing the result of a LINQ query that I would like to use as a parameter for another LINQ query. I am using for Controller: public async Task<ActionResult> Index(String aContainer) { var partsLocations = db.PartsLocations.Include(p => p.LocationType).Include(p => p.ManufacturingPlant); var empty = from y in db.PartsLocations select y; if (!String.IsNullOrEmpty(aContainer)) { var parentLoc = from a in db.PartsLocations where a.LocationName.Contains(aContainer) select a

JPA to GET a joined entity returns a recursive fetch loop

淺唱寂寞╮ 提交于 2020-01-15 09:36:07
问题 I have a problem with a @Get method. I have an entity ServcieChargeTier which has a @OneToMany relationship with the entity CalendarEntry . The problem is when I try and get a ServiceChargeTier from the server, the server returns a recursive loop of the ServiceChargeTier, which has CalendarEntries , which each has a ServiceChargeTier associated, which has the CalendarEntries and so on. I would like to return the CalendarEntry's but not the associated ServiceChargeTier for each CalendarEntry.

Setting a default object for Entity Framework navigation property

a 夏天 提交于 2020-01-15 08:24:14
问题 Is it possible to set a default object for an Entity? Say I have a Person entity that originally did not have a requirement for a Profile . Now I require a Profile - but there are existing entities that do not currently have a Profile . Is there a way I can provide a default object for these Entities when they're loaded in future, so anyone using the Person Entity can assume that Profile is never null and always has a value - even if it's a default. Below you can see what I've tried - which

How to specify a multi-column UNIQUE constraint in code-first Entity Framework fluent API

青春壹個敷衍的年華 提交于 2020-01-15 08:08:05
问题 Suppose I have the following entities: public class Calendar{ public int ID{get;set;} public ICollection<Day> Days { get; set; } } public class Day{ public int ID{get;set;} public DateTime Date{get;set;} public int CalendarID{get;set;} } This is a one-to-many relationship with CalendarID as a foreign key. The issue is I also want to make sure that each date exists only once in each calendar. That is, no two days have both the same Date and same CalendarID . In raw SQL I can do this by: ALTER

Entity Framework Insert stored procedure in a loop

你。 提交于 2020-01-15 07:50:21
问题 Trying to execute an insert stored procedure in a loop using Entity Framework, something like this: var context = new Entities() var items = context.GetAllItems().ToList(); foreach(var item in items) { // Other select and update procedures context.InsertProcedure(item.Prop1); } context.SaveChanges(); but I am getting an exception. New transaction is not allowed because there are other threads running in the session Anybody had this before? 回答1: It turned out there is another exception, but

Entity Framework Insert stored procedure in a loop

江枫思渺然 提交于 2020-01-15 07:50:16
问题 Trying to execute an insert stored procedure in a loop using Entity Framework, something like this: var context = new Entities() var items = context.GetAllItems().ToList(); foreach(var item in items) { // Other select and update procedures context.InsertProcedure(item.Prop1); } context.SaveChanges(); but I am getting an exception. New transaction is not allowed because there are other threads running in the session Anybody had this before? 回答1: It turned out there is another exception, but

ASP.NET LINQ query for filter and loop through multiple tables

落爺英雄遲暮 提交于 2020-01-15 06:31:10
问题 I have two separate domain model classes for "App" and "AgeGroup". The App Class is containing few basic integer and strings properties and so does the AgeGroup class. What I'm trying to achieve is JSON output of all the apps by AppOrder with their properties, nested in their associated AgeGroups that are ordered by their GroupOrder property Required Example JSON Output Structure "Looped List of Age Groups, order by GroupOrder" "Looped List of Apps, order by App Order" First Age Group Foo App

Entity Framework Linq equals value or is null

为君一笑 提交于 2020-01-15 05:53:07
问题 I am trying with linq to get a list of items from a view where the field LocationId is either a value or is null. The field LocationId is int?. The code which i am trying is something like this: var items = _context.Items.Where( d => d.LocationId == null || d.LocationId == query.Location).ToList(); Unfortunately, as seen with SqlProfiler the generated sql does not include d.LocationId == null. What is different from the possible duplicate question is that there where only checking for a value

Update entity with ViewModel and Entity Framework 6?

半世苍凉 提交于 2020-01-15 05:40:12
问题 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