entity-framework

Working with an unsigned BIGINT in SQL Server

I'm trying to store and retrieve an unsigned int64 using Microsoft SQL Server (and ultimately using ADO.NET EF), but I'm having some trouble. Since you cannot specify an integer column as unsigned in SQL Server, I tried using binary(8), however that's not working like I expected. The following queries result in an unexpected value (0x0...

Setting CommandBehavior for executing commands in Entity Framework

How can I specify CommandBehavior (for e.g. SequentialAccess) when executing a command on entities? ...

Does Model Driven Architecture play nice with LINQ-to-SQL or Entity Framework?

My newly created system was created using the Model Driven Architecture approach so all I have is the model (let's say comprehensive 'Order' and 'Product' classes). These are fully tested classes that support the business of my application. Now it's time to persist these classes as objects on the harddrive and at some later time retrie...

Is there a generic way of using AutoMapper's ValueResolver to map EntityKey values for EF Entities?

Not sure if the title makes sense, but here's what I'm doing. I'm using AutoMapper to map my Entity Framework Entities to my DTO objects and vice versa. The issue comes when I try to map the DTO data to the EF entity. There's not a property to property mapping for the EntityKey. To fix this, I do some like the following: Mapper....

Best method of profiling Entity Framework 4 dynamic queries?

What is the best method to profile dynamic queries that the entity framework generates? I've been using Sql Server Profiler so far, but I was hoping that there's a better way in Visual Studio 2010. ...

What's the best way of using xVal when using the Entity Framework?

What's the best way of implementing xVal when using the Entity Framework? I've been using this approach but I'd like to know if there's a better way of doing it. Also I'd like to know if there's a way of doing it without having to raise an exception. ...

Is Lazy Loading really bad?

I hear a lot about performance problems about lazy loading, no matter if at NHibernate, Linq.... The problem is N+1 selects. Example, I want all posts and its users, at foreach I lazy Load Users, them I need one select for posts, plus N select for each user. Lazy Loading: 1 - select ....from post N - select ....from user The "good" ap...

How to set an Id in Entity Framework

When I have an entity object, how do I set the relationship without having the object, just by having the id? Something like: Post.BlogId = 42 ...

Entity Framework - The underlying provider failed on ConnectionString.

While using the Entity Framework I have split it out to it's own project: RivWorks.Model - Contains Entity Model RivWorks.Controller - Uses the Entity Model and contains the biz rules RivWorks.View.Web - The web site RivWorks.View.Services - WCF project Everything in the web site is working fine. I am able to call into the Controll...

Linq replace field for a subquery

Hi, I have a database containing users and roles. The table Users has a reference to the table roles as each user is bind to a role (one and only one). When I use linq to retrieve the users, the field "role" shows in a datagrid as an integer (which is the primary key of the table Roles). However, I'd like to replace the field Role of the...

Is it possible to have the entity framework include the SQL command when it throws exceptions?

My problem is that when I get a SQL exception from the entity framework (say for example, because of a null value that isn't allowed to be null), it's sometimes hard to figure out which property is being referred to, and why it is null. Now I know I can set up a SQL trace and log it which will give me the information I need, but this me...

Entity Framework 4.0 POCO save problems

Hi I'm new to EF 4.0 and I'm trying to use POCO (VS 2010 beta 2) I did everything like it is described in ADO.NET Team blog: 1. Generated edmx from my db 2. Created POCO classes in separate project. The root class looks like this: public class SendHistoryItem:AggregateRootObject { #region Scalar public virtual DateTime ...

How to add a stored procedure that returns a scalar value to Entity Framework model and call it from the Entity Context?

Hi, I have a stored procedure that returns a scalar value, I mapped it in the entity model, created an imported function, however it wasn't add into the context class. So I was not able to found how to call it from C# code. Thanks in advance, Carlos Loth. ...

Is there a neat workaround to the lack of foreign key identity columns in Entity Framework 3.5?

I'm having to downgrade a site from .NET 4 beta 2 to .NET 3.5. The biggest hurdle is all the foreign key identity values I reference/lookup, as this isn't supported natively in EF 3.5. Does anyone know of a reasonable work-around for this? An example of what I mean is: contacts.Where(contact => contact.TypeGuid == guid) [TypeGuid] ...

linq to sql vs ado.net entities

If I am using SQL Server as my database service, is there any compelling reason to look at LINQ to Entities over Linq to SQL? ...

prefetching members of inherited entities via a LINQ-to-Entities query

I think the simplest way I can ask this question is with an example: Suppose that I have an Entity Framework model with an "Order" entity that has an "OrderLines" collection. The "OrderLines" collection is ostensibly a collection of OrderLine objects, but I am using inheritance here, so the actual type of an object in the collection is g...

Best way to transfer an Entity Framework object over the web and back via JSON

I've got some MVC code that serializes an EF 3.5 object into an anonymous type for return as a JSON result to an AJAX call on my page. The hurdle I have is that when I send the object back to the server via JSON, (and let the ModelBinder deserialize it for me into my EF type), I have to update it in my Entity Framework context manually....

Entity Framework, AutoMapper, handling entity updates

I just started using the Entity Framework 1.0 recently and believe I am beginning to feel the pains everyone is talking about. I'm trying to use best practices so I have a set of DTO that get mapped to and from my Entities via AutoMapper. The real catch is when I'm trying to update an object. The first gotcha was that I could not find ...

How to specify metadata location in connection string when using an edmx file

I have a web project with a data model defined in an edmx file. The connection string starts like this: metadata=res://*/; This has worked fine for a while. But somebody else working on the project created a dll that also uses the entity framework and added it to the bin folder. Now when I try to create my connection there is an er...

EF 4 Self Tracking Entities does not work as expected.

I am using EF4 Self Tracking Entities (VS2010 Beta 2 CTP 2 plus new T4 generator). But when I try to update entity information it does not update to database as expected. I setup 2 service calls. one for GetResource(int id) which return a resource object. the second call is SaveResource(Resource res); here is the code. public Resou...