linq-to-entities

.NET TDD with a Database and ADO.NET Entity Framework - Integration Tests

Hello, I'm using ADO.NET entity framework, and am using an AdventureWorks database attached to my local database server. For unit testing, what approaches have people taken to work with a database? Obviously, the database has to be in a pre-defined state of change so that the tests can have some isolation from each other... so I need...

Is LINQ to SQL deprecated?

Back in late 2008 there was a lot of debate about the future of LINQ to SQL. Many suggested that Microsoft's investments in the Entity Framework in .NET 4.0 were a sign that LINQ to SQL had no future. I figured I'd wait before making my own decision since folks were not in agreement. Fast-forward 18 months and I've got vendors providi...

Using ADO.NET Entities LINQ Provider to model complex SQL Queries?

What I find really powerful in ADO.NET Entities or LINQ to SQL, is the ability to model complex queries. I really don't need the mappings that Entities or LINQ to SQL are doing for me - I just need the ability to model complex expressions that can be translated into T-SQL. My question is - am I abusing too much? Can I use the Entity Fra...

Can't get results from a IQueryable.

Hi! I have the following code in Linq to Entity: var policy= from pol in conn.Policy where pol.Product.DESCRIPTION=="someProduct" SELECT pol; Then, the table Policy, has some dependencies for a table called Entity. If I do this: foreach(Policy p in policy){ if(!p.Entity.IsLoaded) p.Entity.Load(); IEnu...

subqueries linq

Hey all I am trying to do a subquery in linq but the subquery is a value and it seems to not be working, can anyone help out? I am using the entit frame work I keep getting and int to string error not sure why. from lrp in remit.log_record_product join lr in remit.log_record on lrp.log_record_id equals l...

Linq to Entities : Many-to-Many join a Table and a View

I have several tables and a view : Tables : - aspnet_Roles (with RoleId & other columns) - Status (with StatusId & other columns) - RoleStatus (with RoleId and StatusId and relationships) When I create the Linq To Entities EDMX file, it creates 2 entities with a Status List property in aspnet_Roles and a aspnet_Roles list in Status. ...

ASP.Net Entity Framework Repository & Linq

My scenario: This is an ASP.NET 4.0 web app programmed via C# I implement a repository pattern. My repositorys all share the same ObjectContext, which is stored in httpContext.Items. Each repository creates a new ObjectSet of type E. Heres some code from my repository: public class Repository<E> : IRepository<E>, IDisposable where...

How to deal with large result sets with Linq to Entities?

I have a fairly complex linq to entities query that I display on a website. It uses paging so I never pull down more than 50 records at a time for display. But I also want to give the user the option to export the full results to Excel or some other file format. My concern is that there could potentially be a large # of records all bei...

How to take Min/Max values for adjacent columns after grouping in LINQ?

Guys I'm newbie to LINQ. Kindly help me out. Following is my scenario... ParaId-------ErrorId 1-------------1 60------------2 125-----------3 126-----------3 127-----------3 128-----------3 129-----------3 247-----------4 248-----------4 249-----------4 Above is the result out of some query.The ErrorId column repeats values. What I wa...

how to select specific number of child entities instead of all in entity framework 3.5?

Hi all, i am wondering how can i select specific number of child objects instead of taking them all with include? lets say i have object 'Group' and i need to select last ten students that joined the group. When i use '.Include("Students"), EF includes all students. I was trying to use Take(10), but i am pretty new to EF and programm...

Creating an entity for a link table in EF4

I have 3 tables Table 1 Id Name Table 2 Id Name Link Table Table1Id Table2Id The link table sets up a many to many relationship between Table 1 and Table 2. I'm using the entity framework which does not automatically create an entity for the Link Table and I need to be able to manage that table directly. Therefore, I need ...

How to store a list in a column of a database table.

Howdy! So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of list I want to create will be composed of un...

C# & ASP.Net - determine linq query generation time

I'd like to detemine the amount of time it takes for my ASP.Net program to generate certain sql queries using linq.... note - I want the query generation time, not the query execution time. Is this possible, or even feasable (if its usually fast)? My website has some heavy traffic and I want to cover all of my bases. ...

want a Query to make order by variable in Linq query

How to make order by Column variable because I have a dropdown on page and I want to show grid according to sord order selected in this Dropdown e.g Price, Code, rating, description etc etc. and I donot want to write a separate query for each column. from lm in lDc.tbl_Products where lm.TypeRef == pTypeId orderby lm.Code ascending se...

Entity Framework SaveChanges - how to ignore ID / Identity fields on INSERT

VB .NET 4 WinForms application. I have a (DevExpress) grid bound to an IEnumerable(Of MyClass). Whenever a new row is added, the ID defaults to zero (0). On trying to SaveChanges, EntityFramework doesn't realise that being an identity field means it should ignore any contents on insert and just insert the other values. I can't specify n...

Cryptic Linq to Entities message

I get the following message: {"Entities in 'Entities.ApprovalRequests' participate in the 'FK_ApprovalRequest_Audit' relationship. 0 related 'Audit' were found. 1 'Audit' is expected."} I'm stumped, does anyone know what to make of it? My EDMX had the FK and is correct, yet every time I get this message. How one would go to debug thi...

How to bind a query with a join to a DataGridView?

Right now, I have created a new Object data source based off from an Object Context from the entity model. I then created a BindingSource and a DataGridView set to this BindingSource. I can add columns which are bound to the data from the TraceLine table. When I set the DataSource, I see values in those columns. However, I can’t seem to...

Linq to Entites and ObjectQuery

Hi I have Person enity which has a 1 : N relationship with Person_Addresses (fields: PersonID, AddressID, ValidFrom). I want to get all Person records and associated Person_Addresses with only latest ValidFrom. How should i do this using ObjectQuery or IQueryable? Edit: I mentioned ObjectQuery and IQueryable because i wanted to have a ...

Constraint on Linq to Entities Include

I have a message table that self joins to itself where Message.ID == Message.Parent. So I have 1 Message with several ChildMessages. This is set up nicely with a Navigation property. The code is currently: var message = from m in soe.Messages.Include("ChildMessages") where m.ID == id && m.IsActive ...

How to query every n-th value from an ordered set of entities

I would like to query an EF 4 entity set for every nth row, such that I get no more than x results. For example, given a set of 1000 names, give me every 100'th name (sorted by name of course) so that I would have 10 results. Is this kind of thing possible with Linq to Entites, in any kind of efficient manner? ...