entity-framework-4

Entity Framework: Entity is cached when update and reselecting it in a stored procedure using a function import

我是研究僧i 提交于 2019-12-24 19:07:08
问题 I'm using EF4 with Visual Studio 2010 and SQL Server 2008 R2. I am selecting an entity. After that I call a stored procedure which updates that entity en reselects it from the database. When I catch the result of the stored procedure in code, I see that the old (previously selected) properties. Obviously I'm looking at the cached entity value. Is there a way to signal EF that my entity was updated? Or a magic property of some sort? My database table (and entity) look something like this:

InvalidOperationException: The property is part of the object's key information and cannot be modified

你说的曾经没有我的故事 提交于 2019-12-24 14:42:06
问题 I'm getting this error when I try to change column value. Here is how I got to this problem: 1) I was needed to add this bit column to an Existing table. ALTER TABLE BooksDB.dbo.Books ADD edited bit NOT NULL DEFAULT(0), 2) Updated my EF model in project. 3) Now when I try to change 'edited' property of entity object, I'm getting the error from Subject line. Why is that? EF object declaration: /// <summary> /// No Metadata Documentation available. /// </summary> [EdmScalarPropertyAttribute

LINQ to Entities does not recognize the method … get_Item(Int32)

*爱你&永不变心* 提交于 2019-12-24 14:36:43
问题 (Please read before marking as duplicate as my particular scenario is unique) I have the following code: // Get each treasure hunt var treasureHunts = dbContext.TreasureHunts.Where(i => i.UserName == User.Identity.Name).ToList(); // Populate each treasure hunt with the list of leaderboard entries for (int i = 0; i <= treasureHunts.Count; i++) { treasureHunts[i].Leaderboard = dbContext.Leaderboard.Where( leaderboard => leaderboard.TreasureHuntId == treasureHunts[i].TreasureHuntId).ToList(); }

Entity Framework map same table that exists in two databases

狂风中的少年 提交于 2019-12-24 13:18:59
问题 What options are available to correctly map the following using Entity Framework: Database 1 tables: Foo, Foo_Assets, Assets Database 2 tables: Bar, Bar_Assets, Assets I have considered mapping Bar, Bar_Assets, Assets as SQL views, or using a different db context when loading these tables from Database 2. The challenge is that although Foo, Bar and their _Assets tables can be treated independently, both databases have an Assets table. How can these tables be correctly mapped to the Asset

EntityFramework mappings - what is wrong with this mapping?

烈酒焚心 提交于 2019-12-24 11:44:59
问题 I'm kind of stuck working out where I'm going wrong with the below entity framework mapping. What I've done is: a) created a Sqlite database (see below, noting Sqlite doesn't allow FK constraints) b) created a blank Entity Data Mode & then created the model from the database c) issue is then trying to add the Model association so it picks up and uses the "ProcessNameId" column I've created in the database in the USAGES table. I've been trying to use the GUI Table Mapping pane to do this but

OptimisticConcurrencyException with Entity Framework on an UPDATE, affects 0 rows

删除回忆录丶 提交于 2019-12-24 11:37:59
问题 I have a data-structure such that: SecurityPolicy 1<---* SecurityPolicyRule Therefore, a SecurityPolicy can have 0, one or many SecurityPolicyRules. I am using Julie Lerman's Entity Framework book to implement some degree of concurrency checking, TDD and POCO support. I understand that each table should have a rowversion/timestamp field, which is marked as ConcurrencyMode==Fixed. I have decided to implement the CUD in Stored Procedures. My UPDATE Sproc is as follows: create PROCEDURE dbo.sp

How to add existing collection of entities to existing entity without pulling first pulling existing entities from database using code-first framework

。_饼干妹妹 提交于 2019-12-24 10:39:44
问题 I'm trying to attach two existing and one new bid bid to an existing auction, but am unable to do so without first pulling the product from the database. This code works, but how would I go about just providing the bid id's for the existing bids and then save the auction using (var db = new DataContext()) //find existing auction var auction = db.Auctions.Find(1); var bid1 = db.Bids.Find(1); var bid2 = db.Bids.Find(2); var bid3 = new Bid() { //New Bid }; //existing auction.Bids.Add(bid1); /

How to do a server-side Insert/Update (Upsert) from Silverlight RIA services

落花浮王杯 提交于 2019-12-24 10:25:36
问题 While RIA services seems very good for table operations & queries, I am stuck on one traditional update situation. The UPSERT (Update if exists, else Insert new): First: I want to add a record server-side if the record does not already exist, otherwise if it already exists, I want to update one of its current field values. Second: I do not want to query the database from client-side, to see if the record exists. I just want to call an "UpsertData" method on RIA services and have the add or

How to Include associated entities

烈酒焚心 提交于 2019-12-24 09:59:10
问题 I want to create test case for below method "GetByEmail". public User GetByEmail(string email, bool includeUserRoles = false, bool includeUserType = false) { Expression<Func<User>> whereClause = u => u.Email == email; return GetQuery(whereClause, includeUserRoles, includeUserType) .FirstOrDefault(); } private IQueryable<User> GetQuery(Expression<Func<User>> whereClause, bool includeUserRoles = false, bool includeUserType = false) { IQueryable<User> query = base.GetQuery(whereClause); if

Should I rip out the Association Fixup code from my Entity Framework T4 Template?

被刻印的时光 ゝ 提交于 2019-12-24 09:30:00
问题 Can someone clarify my thinking on association fixup code in Entity Framework (T4 generated POCOs) please? A recent comment regarding fix-up stated 'For example code-first doesn't use them and everything still works'. I'm a little confused on this fixup stuff - seems no-one likes it - I certainly don't like it polluting my POCOs (though my reason is because of performance issues) yet it is not clear to me in what scenarios would I really need it. If I am using short-lived data context