linq-to-entities

Setting options with Linq

I'm in a situation where I want to add the equivalent of the sql statement SET QUERY_GOVERNOR_COST_LIMIT to my query I created with linq to entities. How would I go about that? ...

NullReferenceException in EntityFramework, how come?

Take a look at this query: var user = GetUser(userId); var sessionInvites = ctx.SessionInvites .Include("InvitingUser") .Include("InvitedUser") .Where(e => e.InvitedUser.UserId == user.UserId) .ToList(); var invites = sessionInvites; // Commenting out the two lines below, and it works as expected. foreach (var invite i...

LINQ TO SQL, ADO.NET Entity Framework, T-SQL

Greetings, I have a few applications/websites running with LINQ to SQL and the other day I decided to go ahead and optimize some of the queries, etc and I found that the size for variable length data types is derived from the parameter value instead of the column actual size? for example a column is defined as nvarchar(30). when I use ...

How to use orderby in IQueryable object?

How to use orderby in IQueryable object? ...

Entity Framework VS LINQ to SQL VS ADO.NET with stored procedures?

How would you rate each of them in terms of: Performance Speed of development Neat, intuitive, maintainable code Flexibility Overall I like my SQL and so have always been a die-hard fan of ADO.NET and stored procedures but I recently had a play with Linq to SQL and was blown away by how quickly I was writing out my DataAccess layer a...

Linq - Orderby not ordering

Hello everyone, I have a linq query that for whatever reason is not coming back ordered as i would expect it to. Can anyone point me in the right direction as to why and what i am doing wrong? Code is as follows: List<TBLDESIGNER> designer = null; using (SOAE strikeOffContext = new SOAE()) { //Invoke the query designer = AdminD...

Is saving to database just to get an ID a bad hack?

I hope the title is not too confusing. I am trying to make folders with linq-to-sql objects' IDs. Actually I have to create folders before I should save them. I will use them to keep user uploaded files. As you can see I have to create the folder with the FileID before I can save it there. So I just save a record which will be edited or ...

linq - how to sort a list

Hello everyone, I have a linq query that populates a list of designers. since i am using the filters below my sorting is not functioning properly. My question is with the given code below how can i best sort this List after the fact or sort while querying? I have tried to sort the list after the fact using the following script but i...

Linq to Entities performance within ASP.NET Development Server

I've been evaluating linq to entities and linq to SQL for a project. Obviously each has its own advantages and disadvantages which have been discussed plenty of times here. However, One thing I am seeing with L2E is kind of odd. Using L2S, when using the ASP.NET Development Server, the performance is a little slower for my web ser...

How to convert this SQL query to Linq to Entity query?

Hi, could you help me please convert this SQL query to Linq to Entity query? Thank you select distinct item, count(item) as count from TableName where ColumnName = @parameter and (ColumnName2 = @parameter2 OR ColumnName3 = @parameter3) group by item order by item asc ...

Linq to Entities custom ordering via position mapping table

Hi, I have a news table and I would like to implement custom ordering. I have done this before via a positional mapping table which has newsIds and a position. I then LEFT OUTER JOIN the position table ON news.newsId = position.itemId with a select case statement CASE WHEN [position] IS NULL THEN 9999 ELSE [position] END and order ...

Linq to Entity convert string to proper case

Could you show me an example how to convert string when I am selecting using Linq to entity to proper case? Thank you ...

"Select NOT IN" clause in Linq to Entities

Hi, Is there a way to use the "NOT IN (select XXX...)" clause in Linq to Entities? All the questions I found were regarding a list of objects (IN (1,2,3)) but I want to generate a query with the following syntax: select * from table1 where field1 not in (select subfield from subtable) Be aware that this is Linq to Entities and not...

Why does this code generate a NotSupportedException?

Why does this throw System.NotSupportedException? string foo(string f) { return f; } string bar = ""; var item = (from f in myEntities.Beer where f.BeerName == foo(bar) select f).FirstOrDefault(); Edit: Here's an MSDN reference that (kind of) explains things... Any method calls in a LINQ to Entities query...

Entity Framework: insert with one-to-one reference

Hi 'overflow! I'm having a bit trouble inserting into a mssql database using Entity Framework. There's two tables that I want to insert into, where one of table 1s fields is a foreign key in table2. This is the code I have so far: Media media = null; foreach(POI p in poiList) { media = new Media() { Path = p.ImagePath...

LINQ to Entities, SQL Server version and setting ProviderManifestToken at runtime

We have developers some developers who are developing against a SQL Server 2005 database, while others are using 2008. We just discovered that generating the edmx against a 2008 database set the ProviderManifestToken to 2008, which means some queries won't work against a 2005 database. While this is a known issue, is there any way to...

Automatically generate buddy classes from model in C#

I use Linq to Sql (although this is equally applicable in Entity Framework) for my models, and I'm finding myself creating buddy classes for my models all the time. I find this time consuming and repetitive. Is there an easy way to automatically generate these buddy classes based on the models? Perhaps a visual studio macro? An examp...

How to join results from two different sets in LINQ?

Hi, I get some data about customers in my database with this method: public List<KlientViewModel> GetListOfKlientViewModel() { List<KlientViewModel> list = _klientRepository.List().Select(k => new KlientViewModel { Id = k.Id, Imie = k.Imie, Nazwisko = k.Nazwisk...

Why LINQ to Entities won't let me initialize just some properties of an Entity?

So I've started to add Entity Framework 4 into a legacy web application (ASP.NET WebForms). As a start I have auto-generated some entities from the database. Also I want to apply Repository Pattern. There is an entity called Visitor and its repository VisitorRepository In VisitorRepository I have the following method: public IEnumera...

How to search between two dates in LINQ to Entity?

I have an example in SQL how to use the same logic in Linq to Entity? SELECT * FROM TABLE WHERE DATE BETWEEN STARTDATE AND ENDDATE ...