entity-framework

Keeping changes to auto-generated WCF RIA Services Domain Classes

During the creation of an auto-generated WCF domain service class based off entity framework, a file that contains the metadata for the EF classes is also created. In this file, I've had to add the [Include()] attribute to a number of classes so that I can include these properties during WCF calls. My problem is, I sometimes have to ch...

Entity Framework and Silverlight foreign key objects

I'm trying to add a new instance of an object to my data source, and there's a foreign key defined for ListUserName. The CurrentUser object is the right type to put into it and is populated correctly, but it blows up on me when submitting it to the data source. This is all pulled from a Domain service class into the Silverlight app. L...

EntityCollection Clear() and Remove() methods

What is the right way to delete all of the collection items of an EF entity? In the code below, DocumentItems is the collection of related document items for a document. This code proceedes on Clear() but fails on SaveChanges() because related items are connected to their document via FK and FK is mandatory. So I guess they somehow remai...

How to set a server side parameter on an a entity data source

I have a gridview which I databind to EntityModel This typically looks like something a something b companyID on Login I get and set the compnay which has the ID so what in essence I want to do is on databind set the Where clause of data source to what the server side paramter for company ID is. I am sure this is super simple but it...

Use EdmGen to generate ssdl, and csdl but NOT generate code?

I am working with a large Entity Framework 4.0 edmx, and need to automate the construction of the edmx. However, I needto maintain the ability to use customized T4 templates. In our edmx, we have code generation set to None, so we can use multiple T4 templates against the edmx. When I build using EdmGen, the code is generated using th...

Sum the difference of two columns in Entity Framework

I am trying to compute the sum of the difference of two columns: var result = model.TableExample .Where(condition here) .Select(s => s.Column1 - s.Column2) .Sum(); but it is rising an exception: Index and length must refer to a location within the string I can't understand th...

EF CTP4 lazy loading not playing ball

I'm using the CTP4 code first EF framework, but I'm having problems getting lazy loading to work. Reading up on it, it should be simple, but it's just not public class Folder { public int Id { get; set; } public string Name { get; set; } public int? ParentFolderId { get; set; } public virtual IList<Folder> ChildFolders...

How can I return if an optional navigation property exists from an Entity Framework Query?

I'm trying to return a boolean value using the following query: var q = from inmate in context.Inmates select new { inmate.Id, IsCrazy = inmate.Certified != null }; IsCrazy should be true only when the optional Certified navigation property is not null. However, IsCrazy is always being r...

Using multiple .Where() calls or && conditions for LinqToEntities queries

Are the following two queries equivalent? If they are not equivalent, which performs better? Is there a way I can see the sql output of the queries? var query1 = items.Where(i => i.Enabled == true).Where(i => i.Name == "Bob"); var query2 = items.Where(i => i.Enabled == true && i.Name == "Bob"); ...

Help with using jQuery with ASP.NET MVC

My app has a "Show all comments" similar to the one in Facebook. When the user clicks on the "show all" link, I need to update my list which initially has upto 4 comments with all comments. I'll show some code first and then ask some questions: jQuery: ShowAllComments = function (threadId) { $.ajax({ type: "POST", ...

Formatting Date on Html.TextBoxFor - other solutions not working.

Using EF-generated classes, here's my metadata class: [DisplayName("Approved Date")] [DataType(DataType.DateTime)] [DisplayFormat(ApplyFormatInEditMode = true, HtmlEncode = false, NullDisplayText = "", DataFormatString = "{0:MM/dd/yyyy}")] ...

entity framework - how can I implement this SQL in the abbreviated EF linq

Can anyone help out with what the C# code would be to implement this SQL as Entity Framework Linq in the abbreviated form? (e.g. where you have the "." notation such as xxx.where(... etc) SELECT PN.Name, Sum(U.Amount) FROM Usages as U, ProcessNames as PN WHERE PN.Id == U.ProcessNameId AND U.Datetime BETWEEN '2010-01-08' AND '2010-1...

LINQ to Entities 4: Query with calculation in where clause.

Hello. I have a table with a DateTime "TimeStamp" column and an int "TimeoutSeconds" column. I want to retrieve all records from this table where DateTime.Now - TimeStamp > TimeoutSeconds. In a stored proc this was a no brainer using GetDate(): select * from Schema.TableName mp where (GetDate() - mp.[Timestamp]) > mp.Timeout However, ...

Entity Framework and Synchronizing a database solution?

I currently have an n-tier application using entity framework 4.0 and we're looking at synching the contents of database between redundant servers. Does anyone have any experience on tips on how best to approach a solution? ...

Entity Framework; Object-Oriented delete

Hi I'm building out a stock management system at the moment, using Entity Framework 4. A little background, my entities go a bit like this (only showing needed info) Product --> ProductLocations WarehouseLocation --> has many ProductLocations Each ProductLocation has a Quantity What I'm trying to do is have it so that when you call...

Chaining MapHierarchy() to add more Cases in EF code first

I'm hoping there will be a crazy linq answer to this, it feels like there should be Current code: MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, f.Name, Type = 1 }) .Case<RootFolder>(f => new { f.RootName, ...

How can I retrieve a subset of data from entity object data source and pass to another page

I am playing about just now trying to teach myself a little bit about the entity framework. I have a Gridview data bound to a Entity Date Source using the Entity Framework. If I select certain items in that list I then wish to redirect another page and populate another gridview with just the items selected (but with more detail, differ...

Entity Framework Invalid Object Name Error

I'm using VS2008 to connect to a SQL server database in order to populate it in C#. It's going pretty well, I'm able to query, insert, and update all tables in my database successfully, except one. Anytime I try to query or insert into one table I get the following error: Message = "Invalid object name 'DB_NewModelStoreContainer.DATATYP...

Entity Framework 4 : Bad performance with SQL Server 2008

I'am developing a software based on Entity Framework to handle data in a MS SQL Server 2008 database. [Trouble 1] I've just tried to insert some small data (about 2 Mb) from my progam to the database : the performance are very bad ! It takes more than 1 minute to insert these datas ! I've try to generate pre-compiled views, I've got t...

Entity Framework - First query slow

Hello As the title suggest i'm having a problem with the first query against a MS SQL database using the Entity Framework. I have tried looking for an answer on different sites but no one seems to actually have a solution to this. I'm loading quite a lot of rows from the database including two 0-many relationships. The tests was done i...