linq-to-entities

LINQ ".Include" orderby in subquery

I have the following entity code, which returns all users and "includes" all of their sample requests: var userQuery = from u in _IntranetContext.UserSet.Include("SampleRequests") orderby u.LastName ascending select u; Each user has multiple SampleRequests. Each SampleRequest h...

best practise/way for master detail / multi table Insert in Entity Framework

My table structure is this Orders ------ Id int identity OrderDate smalldatetime OrderStatusid tinyint Products -------- Id int identity Name varchar(50) OrderDetails ------------ Id int identity OrderId int (fkey) ProductId int (fkey) Amount decimal Rate decimal I am trying to an insert operation using Entity Framework using the c...

Ado Net Data Services BeginExecute Problem

public void metodoX() { foreach (TURNO t in listaTurnoPersona) { DataServiceQuery<VST_CANTIDAD_PERSONAS_POR_DIA> query = General.Entities.VST_CANTIDAD_PERSONAS_POR_DIA.Where( z => z.ID_TURN == t.ID_TURN && z.FE_CALE >= RadDatePicker1.SelectedDate.Value && z.FE...

How to tell if an IEnumerable<T> is subject to deferred execution ?

I always assumed that if I was using Select(x=> ...) in the context of LINQ to objects, then the new collection would be immediately created and remain static. I'm not quite sure WHY I assumed this, and its a very bad assumption but I did. I often use .ToList() elsewhere, but often not in this case. This code demonstrates that even a si...

Entity framework linq to entities

Previously when I wanted obtain related data in an sql query I would join tables, however now in linq to entities I want to get data from a table that is related to the table through another table. I don't know how to perform this sort of query in linq to entities. If someone could help that would be good. The example is a table named p...

Linq Query on int using string

I'm trying to query the unique reference number of a table using Linq to Entities. The ID is provided via a textbox and hence a string in my code. Obviously in the database table the field is an integer so I have tried using .ToString first and then .Contains in the same way you would with a varchar(). This doesn't seem to work, with the...

When do LINQ-to-SQL queries execute?

I just want to confirm... LINQ-to-SQL queries never execute (hits the database) until it is enumerated, right? Does anyone know if this is the same for LINQ-to-Entities? Thanks! ...

LINQ to Entities on (database != Microsoft SQL Server)

My production is on full blown SQL Server 2008. I would like to have integration tests with some light weight database that doesn't have to be installed on the machine and doesn't run as a service ...if at all possible. I use LINQ to Entities in my code that probably makes this goal even more complicated. Is it possible to use any...

Compare 2 Entities

I have an entity that has a 1-to-many relationship with another ( Entity Position has One Department). In the details view I'm showing in s combobox a list of all the departments available and I want to start the selecteditem in the combo is the department to which the entity is related. The problem is than I am using layers so the Pos...

Cannot retrieve user object from foreign key relationships using Linq to Entities statement

Hi, I'm trying to retrieve a user object from a foreign key reference but each time I try to do so nothing gets returned... My table is set up like this: FBUserID long, UserID uniqueidentifier so I have my repository try to get the User when it's provided the FBUserID: public User getUserByFBuid(long uid) { User...

How to select an object through a foreign key

If I have a table with a primary key (AccLinkID) and a foreign key (aspnet_Users UserID), how can I select the object that the foreign key points to using Linq to Entities. User myUser = _myDB.AccLinkSet.Where(user => user.LinkID == linkId).FirstOrDefault().aspnet_Users; did not work... anyone have any ideas? ...

Linq int to string

Hi, how do I cast and int into a string? None of the following do works: from s in ctx.Services where s.Code.ToString().StartsWith("1") select s from s in ctx.Services where Convert.ToString(s.Code).StartsWith("1") select s from s in ctx.Services where ((string)s.Code).ToString().StartsWith("1") select s EDI...

Creating Enums from Entities

I have tables named Events and Log. The Events table comprises of ID, Event description and type. And, the Log contains LogID, EventID(refers to ID from Event table), and timstamp. I am using Entities framework. While making an entry in the log table, i mention the event id as the number corresponding to the log event from the Event ta...

What is the best way to cast each item in a LINQ to Entities query to in interface?

I have an entity object 'User' which implements 'IUser': IQueryable<User> users = Db.User; return users; But what I actually want to return is: IQueryable<IUser> So what is the best way to convert IQueryable<User> to IQueryable<IUser> without actually running the query? Right now I am doing this but it seems like a hack: IQ...

Is this possible with LINQ-to-Entities query using Lambda Expression

Looking for direction and understanding of the approach to implement logic to handle the scenario below, if possible with LINQ-to-Entities. New to LINQ and Entity Framework, but understand the basics. Intermediate with C#. I have a function, which needs to iterate through and add information to a results set and ultimately pass back t...

MVC using Linq to Entity w/ sql encryption

Currently i am using sql encryption and would like to continue using it through Linq. I have all my CRUD stored proc's wired up to the table in order to handle the encryption/decryption on the backend. Problem is my database model see's a field type of varbinary(max) which is used for the sql encryption storage. The retrieval sp for t...

Linq to entities

I was wondering how i compared to an array of ids in EF1.0 I know in EF4.0 Beta 1 there is a contains methods so it would look something like this int[] associationIds = GetAssociationIds(); from c in Associations where c.AssociationId.Contains(associationIds) select c; But how do you do the equivalent in EF1.0 ...

Left Outer Join in Linq-To-Entities

Is there a way to do a left outer join in linq-to-entities WITHOUT having tables mapped with foreign keys? Also, if our company decides to stick with using linq-to-entities despite all of its current flaws, do you think it's important to get Visual Studio 2010? In other words, what is in Visual Studio 2010 that would help developing wit...

Dynamic Where for List<T>

I'm trying to create a dynamic filter for various classes. We would only know at runtime what type we're dealing with. I need the ColumnName to be the actual column (not a string value). Is there an easy way to convert the string into a column? public static List<T> Filter<T> (this List<T> Source, string ColumnName, ...

LINQ-to-Entities or Entity SQL query

I need a LINQ-to-Entities or Entity SQL based query to handle the following scenario: Users belong to one or more Locations. Shipments belong to exactly one Location. Batches contain Shipments. Users should only see Batches where ALL of the Shipments in the Batch are from Locations they have access to. Example Batch: Shipment_1.Lo...