entity-framework-5

“Unable to create a constant value of type 'User'” when using FirstOrDefault?

谁都会走 提交于 2019-12-06 08:36:49
问题 I have a method called UpdateOrders that is supposed to allow users to only edit orders that they own, unless the user is an administrator, in which case they can edit all orders. I'm using Entity Framework 5 in .NET 4.5. The following code produces the error "Unable to create a constant value of type 'User'" at the line var target = _context.Orders.FirstOrDefault... . public Order UpdateOrders(Order order) { var userName = HttpContext.Current.User.Identity.Name.ToLower(); var target =

Cloning Object with many-to-many relationship in EntityFramework

自作多情 提交于 2019-12-06 07:55:06
All I want is just to create an exact copy of an object. I have a class [Serializable] public class Project { public int Id { get; set; } public String Name { get; set; } //navigational fields.. public virtual List<BusinessRequirement> BusinessRequirements { get; set; } } and another [Serializable] public class BusinessRequirement { public int Id { get; set; } public String Name { get; set; } public String Description { get; set; } public virtual List<Project> Projects { get; set; } } so somewhere I've configured the many-to-many relationship b/w Project and BusinessRequirement like this:

Entity Framework selection query

▼魔方 西西 提交于 2019-12-06 07:21:48
问题 I am making a simple application for insert, update, delete, select data with Entity Framework I already made insertion, deletion and select all data. Now I want to select with where condition with filter of two fields For ex : I have table with userid username password email Now need selection like where email = "" and password = "" I know how to write query in SQL but having not clues with entity framework . Also need to store this result in datatable and looping solution both for learning

Using UserProfile foreign key in class creates new profiles in MVC 4

情到浓时终转凉″ 提交于 2019-12-06 07:17:35
I'm trying to make a basic website that uses the built in MVC user profile as the authentication method. I'm using MVC4.0 and Entity Framework. I have a main data class that uses the UserProfile model as a foreign key. This class is a "game" class, for the purpose of relating a game to a certain user. I've also added another member to the UserProfile class, as a necessity for this project. Every time I try to add a new game, which has a user's profile in it as a foreign key, the server ends up making a new user profile altogether, even though I specifically made it so that it's the same user.

UOW and Repository Pattern in EF5

核能气质少年 提交于 2019-12-06 05:37:00
问题 This is about some confusion I have about some of the entity framework material I have found from here: https://www.asp.net/ On this Page it explains how to wrap a dbcontext using a repository and to wrap a repository using a a unit of work class: http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application However, on this page it states that a dbcontext is already a combination of

.Net Entity Framework to CSV

两盒软妹~` 提交于 2019-12-06 05:14:41
I'm using the latest Entity Framework with DBContext. I have a result set that I want to convert to comma separated values. I've done something similar with DataTables in VB DataTable to CSV extraction . I've got the QuoteName method working. I've also get a derivative of the GetCSV method working using a foreach. The problem is that it is a lot slower than the comparable code for a DataTable. So I'm hoping someone will have some suggestions. public static string GetCSV(this IQueryable entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Type T = entity.ElementType; var

Entity, dealing with large number of records (> 35 mlns)

对着背影说爱祢 提交于 2019-12-06 05:10:50
问题 We have a rather large set of related tables with over 35 million related records each. I need to create a couple of WCF methods that would query the database with some parameters (data ranges, type codes, etc.) and return related results sets (from 10 to 10,000 records). The company is standardized on EF 4.0 but is open to 4.X. I might be able to make argument to migrate to 5.0 but it's less likely. What’s the best approach to deal with such a large number of records using Entity? Should I

Value does not fall within the expected range error

限于喜欢 提交于 2019-12-06 04:48:55
问题 I'm developing an ASP.Net MVC 4 application. I have a module that sends out the invoice in an email (using MVCMailer) for some reason at I get the error: Value does not fall within the expected range If I step through the code it works without any error but as soon as I just run it it gives me that error. The section producing the error is: return Populate(x => { x.From = new System.Net.Mail.MailAddress("Sales@Scheduler.com", "Scheduler"); x.Subject = System.Configuration.ConfigurationManager

Can't get the ApplyCurrentValues(Entity) to work in Entity Framework 5

拈花ヽ惹草 提交于 2019-12-06 04:23:09
问题 Comrades, can anyone help me out here, entity framework 5 seems not to have ApplyCurrentValues() method. Is there another way to update the database object in entity framework v5. here is what am trying to do odc.Accounts.Attach(new Account { AccountID = account.AccountID }); odc.Accounts.ApplyCurrentValues(account); odc.SaveChanges(); But i have been getting compile error in the ApplyCurrentValues() line 回答1: ApplyCurrentValues is an ObjectContext API method, so first you have to gain access

Entity Framework Many to Many query

百般思念 提交于 2019-12-06 03:56:44
I want to write a simple query, but there are some problems. I have 2 tables M to N: Users -> Events. I want to get all users of a specific event (get this event by eventId). public IQueryable<User> GetUsersByEventId(int eventId) { IQueryable<User> query = this.Context.Users.AsQueryable(); return query.Where(x => x.Events.SingleOrDefault(e => e.EventId == eventId)); ?? } Something is missing and I dont know what, can someone help me? Thanks a lot ! If I understand you correctly (adding your models would help), I think you want Any public IQueryable<User> GetUsersByEventId(int eventId) { return