linq-to-entities

Modeling relational tables into a single object - ASP.NET and Entity Framework 4

I am writing a blog using ASP.NET MVC2 and using EF4 as the ORM. I want to use Tags for navigation instead of traditional categories. Tables: Post Table - Id - Title - Body - Slug - PostDate PostTags Table - PostId - TagId Tags Table - Id - TagName I want to be able to get a Post object that includes a list of associated Tags. I am ...

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...

Silverlight Databind to a parametrized DataService

Hi, I'm building a Silverlight app using RIA Services. I want to implement a master/detail behaviour. The trick here is that the "detail" grid can not be filled directly with the "SelectedItem" property of the master grid, and what I have to do is get one of the fields from the master grid and use it as a parameter to the DataService. Ho...

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? ...

Error, method not supported by LINQ to Entities

Why I am getting this error: The method 'Single' is not supported by LINQ to Entities. Consider using the method 'First' instead. public ActionResult Details(int id) Line 27: { var result = (from d in _db.MovieSet Line 29: where d.Id == id Line 30: select d).Single(); // ...

linq to entites left outer join

I am struggling linq to entities left outer join. I have two entities (tables): Listings { ListingID, MakeID (nullable) } Makes { MakeID, Description } I want to write something like this in LINQ: select listings.listingID ,listings.makeid , IsNull(makes.Description, 'NA') from listings left outer join makes on list...

LINQ to Entities - Support for Closures (Lambdas) ?

Hey all I've been working around a problem I have when using LINQ to Entities when using closures. Apparently, L2E does not support closures. Meaning: var users = from user in UserRepository.FindAll() select new UserDTO { UserId = user.UserId, Tickets = from ticket in TicketReposit...

How do I deal with the quantity column of a junction table using sql to entities

Hi I have 3 tables. Blog and Tag have a many to many relationship. BlogTag is a junction table with a quantity column. **Blog** BlogID Title **Tag** TagID Name **BlogTag** BlogID TagID Quantity I'm not sure how I handle the quantity column. I'd like it to store how many Blogs have a certain Tag Name How do I deal with the quantity...

LINQ sorting, doesn't work

I have a LINQ query like this: from i in _db.Items.OfType<Medium>() from m in i.Modules from p in m.Pages where i != null && i.Type == 1 && i.Published == true && p.PageId == 2 select p I use the query like this because I have strongly typed view (ASP.NET MVC). I need to have items sorted by the i.Sort property. orderby i.Sort and i....

LINQ to Entities and SQL Injection

I've seen a couple of conflicting articles about whether or not L2E is susceptible to SQL injection. From MSDN: Although query composition is possible in LINQ to Entities, it is performed through the object model API. Unlike Entity SQL queries, LINQ to Entities queries are not composed by using string manipulation or concatenation, ...

Problem with entity framework with inheritance, condition, and foreign key.

I just started to play around with Linq to entities and ran into an issue I can't figure out. I know this doesn't tell everything but to make it easier to understand here is a screen shot of the culprit... I am getting this error: Condition member 'RelatedResources.TypeID' with a condition other than 'IsNull=False' is mapped. Either r...

How to Export data to Excel using LINQ to Entity?

Hi I have the data coming from Entity Data model table on my ASP.NET page. Now I have to export this data into Excel on button click. If it is using OLEDB, it is straight forward as it is here: http://csharp.net-informations.com/excel/csharp-excel-oledb-insert.htm Here is my function to read data from inquiries table: var model = fr...

Query Extension for LINQ

I have some code for strongly typing Includes()'s in linq, like so... public static ObjectQuery<T> Include<T>(this ObjectQuery<T> mainQuery, Expression<Func<T, object>> subSelector) { return mainQuery.Include(((subSelector.Body as MemberExpression).Member as System.Reflection.PropertyInfo).Name); } /// <summary> ...

restrict num of items loaded in navigation property

Hi All, I have the following query in Linq: var query = from question in context.Questions.Include("QAnswers") join answer in context.Answers on question.id equals answer.qst where answer.user == param_userID select question; return query.toList(); The problem is that it doesn't...

Same data being returned by linq for 2 different executions of a stored procedure?

Hello I have a stored procedure that I am calling through Entity Framework. The stored procedure has 2 date parameters. I supply different argument in the 2 times I call the stored procedure. I have verified using SQL Profiler that the stored procedure is being called correctly and returning the correct results. When I call my method...

Linq to Entities: How do I pass an IQueryable to a Method

I am really baffled on this one. I am trying to pass my posts vaiable to a method. How do I go about doing this: var posts = from p in context.post where (p.post_isdeleted == false && (object.Equals(p.post_parentid, null)) select new { p.post_date, p.post_id, ...

How to do a "join" in a LINQ query against the Entity Framework

I have the following table structure which has been imported into the Entity Framework. I need to write a LINQ query where I select the entities of Table1, where a field in Table2 is equal to true, and a field in Table 3 is equal to a specific GUID. Could someone help with this? Thanks you. ...

Linq to Entities: adding a where condition to a child relationship

For example I have a list of customers which each have a list of orders. Now, I want to get a list of all customers with unpaid orders (let's say this is status 2). Together with that list of customers, I want to have the list of unpaid orders also. For example I have this: from c in mycontext.Customers.Include("Orders") select c Whe...

Linq2Entities, many to many and dynamic where clause

Hi, Im fairly new to Linq and struggling using dynamic where over a many to many relationship. Database tables are like so: Products <-> Products_SubCategories <-> SubCategories with Products_SubCategories being a link table. My full linq statement is db.Products.Where("it.SubCategories.SubCategoryID = 2") .In...

Entity Framework and Link Table issue

Hi, I have a database which consists of the following: ** Table 1 ** Id (PK) Field1 ** Table 2 ** Id (PK) Field2 ** Link Table ** Table1Id (FK) Table2Id (FK) The problem is, I cannot access Table 2 from Table 1, even though the relationship exists in the database. For example, the following should be possible: var Results...