entity-framework

How to relate entities that are not directly mapped through a navigation property

I have an object that has been populated with the contents of four different related entities. However i have another entity in which i cannot include as part of the query due to it not being related in the navigation properites directly to the IQueryable table i am pulling. The entity i am trying to include is related to one of the fo...

DateTime comparison in ObjectQuery.Where

I'm using Entity Framework, and I have a COMMENT entity. A COMMENT has a DATEMODIFIED property, which is a Nullable Date. I'm trying to build a query that will filter COMMENTs by date, so I create a startDate object, and do the following: Dim q As ObjectQuery(Of COMMENT) = _ (From c In model.COMMENT Select c) If startDate.HasValue...

Performance cost of creating ObjectContext in every method in Entity Framework v1

Hello, While using .NET 3.5 SP1 in ASP.NET MVC application, the ObjectContext can have lifetime on one Http Request OR of a SINGLE method. using (MyEntities context = new MyEntities ()) { //DO query etc } How much is increased performance cost of creating ObjectContext in every method VS per request ? Thanks. ...

Attaching Entities when using ObjectContext having lifetime of Http Request

Hello, I'm using .NET 3.5 SP1 in ASP.NET MVC application. While using ObjectContext with Http Request lifetime, and trying to attach an entity ALREADY present in context, we get error: "An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key." For Exa...

Pluralization service in Entity Framework - Visual Studio 2008?

Does any one know if there is kinda implementation/addon for VS 2008 SP1 for pluralization service in entity framework like there is gonna b in vs 2010? example: In database: Entity Order ---OrderId ---CustomerId ---OrderDate Entity Customer ---CustomerId ---Name In EDM: Order.Customer Customer.Orders DataContext.Orde...

sql / linq to entities: group on group of hours

Hi, i have a table with snow data which i get delivered per hour. so for instance at between 0am and 1 am 1 cm snow will fall, between 1 am and 2 am 3 cm snow will fall, between 2 am and 3 am 0 cm snow will fall, between 3 am and 4 am 2 cm snow will fall etc. so the table has a Snowdate column (datetime), a Snowdate hour column (int) an...

Moving to Entity Framework v4

I know that EFv4 is still in Beta2, but I would like to hear your opinions: When are you considering to make the move from EFv1 to EFv4? Are you waiting for the final version of .NET Framework 4.0? Will you move (or planning to move) your current project's Data Acess from EFv1 to EFv4? When will you start? Would you use current EFv4 Be...

Context.savechanges is not working Entity Framework

Here is my code Using Context As New NotificationManagerEntities1 Dim User = Context.Users.First() User.Firstname = "Shawn" User.Lastlogin = Today.Date Try Context.SaveChanges() Catch ex As Exception End Try End Using This executes fine with no exceptions, but when i ...

How can I make the Entity Framework generated SQL cleaner

I am using the Entity Framework with SQL Server Express 2008. When using the profiler, I see SQL being generated like this: SELECT [Project1].[C1] AS [C1], [Project1].[EmployeeID] AS [EmployeeID], [Project1].[FirstName] AS [FirstName], [Project1].[LastName] AS [LastName], [Project1].[Active] AS [Active], [Project1].[Updated] AS [U...

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

I have an ASP.NET MVC application where I am editing an existing database to update a paticular field, DateTime. My database has 4 fields, two of which are DateCreated and DateModified. When I try to update the field, I want to keep DateCreated time the same, no reason to update the date it was created, and I change the DateModified time...

Should I Use Entity Framework, DataSet or Custom classes?

Hi Guys, I am really having a hard time here. I need to design a "Desktop app" that will use WCF as the communications channel. Its a multi-tiered application (DB and application server are the same, the client goes through the internet cloud). The application is a little complex (in terms of SQL and code logics) then the usual LOB appl...

Problems Mapping Composition Relationships using Entity Framework

I'm trying to model my domain model using the entity framework. An example is Page class containing a Content class. public class Page { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual Content PageContent { get; set; } } public class Content { public IList<Version> Versions { ge...

asp.net MVC fetching data with table relations

Hello, I have created my Database which has: Artist, tracks and TracksPerArtists I can do sql queries through the entity model. For example when I make: database.TRACK.ToList() I get the list of track to be shown on index view for example. But my foreign keys come empty. While there is an artist and a track, and the correct row for ...

Entity Framework - Mapping decimal(13,0) problem

Hi, I'm migrating the aplication of my company (that nowadays run over SQL Server and Oracle) to ASP NET MVC and Entity Framework for persistence. A create my Entity Model based on SQL Server Database e separately I create a SSDL for Oracle (for Oracle I use DevArt dotConnect for Oracle Provider) and I get some pain troubles. My table...

Update only the changed values on Entity object

Hi, how can i automatically update my entity objects changed values and save them to db. I hava an Action like that public ActionResult Update() { User userToUpdate = new User(); TryUpdateModel<User>(userToUpdate,ValueProvider); BaseRepository.Context.AttachTo("User",userToUpdate); BaseRepository.Context.Sa...

How to do the opposite of eager-loading in Entity Framework?

I understand in Entity Framework you can specify relationships that need to be joined with Include: Product firstProduct = db.Product.Include("OrderDetail").Include("Supplier").First(); But we have the opposite issue that a simple LINQ statement is getting making too many JOINs on the SQL server. So how do we do the opposite...

How to set Foreign Key object using Entity Framework and FluentHtml

What I'm looking to do is set a Foreign Key object in an EF entity via FluentHtml. I have an entity of Foo with a reference to the object Bar via Foo.Bar. What I am trying to do is set the value of Bar in my view form. My models contains a collection of all Bars via Model.Bars. In my view I'm simply using <%= this.Select(m => m.Foo.Bar)....

Visual Studio 2010 Beta 2 and Entity Framework walkthrough

I am in the process of evaluating Visual Studio 2010 Beta 2 and looking for possible replacements for current our data access layer. The Entity Framework looks like a promising replacement to the data retrieval functionality in our applications. Does anyone have a great walk-through/tutorial that demonstrates how to use the Entity Fram...

How to relate entities without navigation property mappings

Hi, I Have Database that contains 4 tables TABLE TBLCARTITEM (CART_ID, ITEM_ID, PROMOTION_ID, many more cart item fields) TABLE XREFCARTITEMPROMOTION (CART_ID, ITEM_ID, PROMOTION_ID) TABLE TBLPROMOTION (PROMOTION_ID, PROMOTION_TYPE_ID, many more promotion fields) TABLE LKPROMOTIONTYPE (PROMOTION_TYPE_ID, PROMOTION_TYPE_DESCRIPTION)...

Running sql in entity framework?

Is there any way to run a sql statement straight from the entity framework generated calls? Or will I have to create a procedure then call that via the entity framework? ...