entity-framework

How do I delete multiple rows in Entity Framework (without foreach)

I'm deleting several items from a table using Entity Framework. There isn't a foreign key / parent object so I can't handle this with OnDeleteCascade. Right now I'm doing this: var widgets = context.Widgets .Where(w => w.WidgetId == widgetId); foreach (Widget widget in widgets) { context.Widgets.DeleteObject(widget); } context...

Entity Framework Model with inheritance and RIA Services

Hi, We have an entity framework model with has some inheritance in it. The following example is not the actuall model, but just to make my point... Let's say Base class: Person Child classes: Employee, Customer The database has been generated, the DomainService has been created and we can get to the data: lstCustomers.ItemsSource ...

Silverlight and RIA Services - The Data sources window does not show anything

Hi, So following some of the examples out there I created a new Silverlight Navigation application with RIA services enabled. Built the entity model, added a domain service and tested whether or not I could get some data to the client. This works fine. But many of the examples show off how they use the Data Sources window to simply drag...

entity framework - getting null exception using foreign key

Having some trouble with what should be a very simple scenario. For example purposes, I have two tables: -Users -Comments There is a one-to-many relationship set up for this; there is a foreign key from Comments.CommentorID to Users.UserID. When I do the LINQ query and try to bind to a DataList, I get a null exception. Here is the code...

entity framework insert bug

I found a previous question which seemed related but there's no resolution and it's 5 months old so I've opened my own version. http://stackoverflow.com/questions/1545583/entity-framework-inserting-new-entity-via-objectcontext-does-not-use-existing-e When I insert records into my database with the following it works fine for a while ...

Different EF Property DataType than Storage Layer Possible?

Hi, I am putting together a WCF Data Service for PatientEntities using Entity Framework. My solution needs to address these requirements: Property DateOfBirth of entity Patient is stored in SQL Server as string. It would be ideal if the entity class did not also use the "string" type but rather a DateTime type. (I would expect this t...

[EF 4 POCO] Problem with INSERT...

Hi all, I'm so frustrated because of this problem, you have no idea... I have 2 classes: Post and Comment. I use EF 4 POCO support, I don't have foreign key columns in my .edmx model (Comment class doesn't have PostID property, but has Post property) class Comment { public Post post { get; set; } // ... } class Post { publ...

Should I remove all inheritance from my model in order to work with ria services?

I've posted some questions on this before, but it's different. So consider a small portion of our model: Person Customer Employee Spouse Person is the base class which has 3 classes that inherit from it. These 4 are very central in our design and link to many other entities. I could solve all the problems I'm experiencing with ri...

Updating with Related Entities - Entity Framework v4

Hi, I use Entity Framework V4 and i want to update Customer who have Visits. My code : EntityKey key; object originalItem; key = this._modelContainer.CreateEntityKey("Customers", customer); if (this._modelContainer.TryGetObjectByKey(key, out originalItem)) { this._modelContainer.Ap...

I need help solving a rather weird error in a WCF service.

Hi.. I have a solution that contains three projects. A main project with my MVC app, a silverlight application and a (silverlight enabled) WCF service project. In my silverlight project i have made a Service Reference to my WCF service. And i pretty much got that working. In my WCF service i have a method that returns an Book object, ...

Entity Framework 4 relationship management in POCO Templates - More lazy than FixupCollection?

I've been taking a look at EF4 POCO templates in beta 2. The FixupCollection looks fine for maintaining the model correctness after updating the relationship collection property (i.e. product.Orders it would set the order.Product reference ). But what about support for handling the scenario when some of those Order objects are remove...

edmx - The operation could not be completed - After adding Inheritance

Hey guys I have an edmx model which I have draged 2 tables onto - One called 'File' and the other 'ApplicaitonFile'. These two tables have a 1 to 1 relationship in the database. If I stop here everything works fine. But in my model, I want 'ApplicaitonFile' to inherit from 'File'. So I delete the 1 to 1 relationship then configure 'Ap...

Is there a way to add or remove a line of an LINQ to DB Query based on if the value being checked is null?

If I have a query like this: String Category = HttpContext.Current.Request.QueryString["Product"].ToString(); IQueryable<ItemFile> pressReleases = from file in connection.ItemFile where file.Type_ID == 8 && file.Ca...

Calculating monthly reports or statistics - MVC Entity Framework LinQ

Hi I am using MVC (C#) and the Entity Framework. I have a sql server database with tables called Profile, Gallery, ArtWork : PROFILE: UserName, FirstName, etc... GALLERY: GalleryID, UserName, GalleryName, ARTWORK: ImageGuid, GalleryID, Description, PublishDate, Views, Downloads, I have the following relationship between the tables: ...

How to serve a View as CSV in ASP.NET Web Forms

I have a MS SQL view that I want to make available as a CSV download in my ASPNET Web Forms app. I am using Entity Framework for other views and tables in the project. What's the best way to enable this download? I could add a LinkButton whose click handler iterates over the view, writes its CSV form to the disk, and then serves that fi...

Sql Server xml column with Entity Framework - how to keep insignificant whitespaces

Sql server 2005 (even 2008) strips the insignificant whitespaces by default. To keep one can use the CONVERT funtction with the last argument as '1' (Ref. Article). How can we do the same thing in Entity Framework? thanks ...

Using Entity Framework with an SQL Compact Private Installation

I am using Entity Framework 4 in a desktop application with SQL Compact. I want to use a private installation of SQL Compact with my application, so that my installer can install SQL Compact without giving the user a second installation to do. It also avoids versioning hassles down the road. My development machine has SQL Compact 3.5 SP...

Entity Framework: Shipping code?

I'm doing a talk on the Entity Framework at a local user group next week. I'll be mentioning my own experience with the Entity Framework and I'd like to include other real world experience with the EF. My questions: Have you shipped a product that uses the Entity Framework? If so, what industry/market? If you haven't used the Entity F...

When are SQL views appropriate in ASP.net MVC?

I've got a table called Protocol, a table called Eligibility, and a Protocol_Eligibilty table that maps the two together (a many to many relationship). If I wanted to make a perfect copy of an entry in the Protocol table, and create all the needed mappings in the Protocol_Eligibility table, would using an SQL view be helpful, from a perf...

"like" queries in Entity Framework

How do I get wildcard text searches (like SQL's "like" statement) in ASP.net MVC using the edo entity framework? I assumed this would work: var elig = (from e in _documentDataModel.Protocol_Eligibility_View where e.criteria.Contains(query) select e); But it returns no results even when searching for a query st...