linq-to-entities

LINQ to Entities Domain Service

I have a domain service, derived from LinqToEntitiesDomainService<FOOEntities> It has one method, IQueryable<Bar> GetBar(). GetBar returns a LINQ query on the entity model. The LINQ works fine in LINQPad. In the XAML of a Silverlight thingy, I have a ListBox whose ItemsSource points to a DomainDataSource defined in the same XAML file,...

How to write WHERE IN query in LINQ to Entity?

Possible Duplicate: 'Contains()' workaround using Linq to Entities? Hi every one. I would like to know how to write the "WHERE IN" query in LINQ to Entity. I have tried with the following code: string[] strings = GetRequest("userID").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); List<long> longs = strings....

Get sub collection in List<class> form

Hello, I have a LINQ to EF query that returns data in a class form. The class has a List<RecipeCategories> property that I need to populate. The RecipeCategories table is a relationship table between the Recipe table and the RecipeCategories table, and can be many to many. I found enough information to get the code to compile, but it er...

Problem with a Simple LINQ To Entities Query

I have a very simple LINQ To Entities query as follows: var orderID = 1; var orders = (from o in db.Orders where o.OrderID == orderID select o).SingleOrDefault(); Can anyone tell me why this query wouldn't work? It doesn't even not throw an exception. I have also checked the SQL profiler and the ...

Can I do a "Take(x)" on the "Include" entity in a Linq Query?

Hi folks, i've got a really simple linq to entites statement :- var query = (from q in Users.Include("UserHistory") select q).Take(20); works great ... except that, for each user .. the history can be n+1. Some users have 100's of UserHistory records. So, can I restrict the the number of UserHistory records to .. 10 or 5...

LINQ to Entity Column Named From

I have an existing database that I'm access with LINQ to Entity in .NET 3.5 and I've run into an issue. One of the tables has a column named "from". This ends up screwing up LINQ when I try to join on it because from is a special word. Is there any way around this? I'm trying to avoid renaming that column since a lot of other things a...

Is there a way to change EntityKey and ExtensionData access to protected when using Linq-to-entities and WCF?

I have been looking at using Linq to entities with WCF for some projects that we are doing. Everything so far has worked out great but there is one thing that I am not so sure about. Linq-to-entities is creating objects which have EntityKey and ExtensionData properties. I am happy about their access in the service but concerned about the...

LINQ Performance Problem

I have a Joomla site that uses JomSocial. I have a .NET web app that I'm working on that will eventually replace Joomla since I prefer .NET over PHP. Right now I have .NET mobile site that users are using. LINQ to Entity has made development very speedy, but I'm now in the process of trying to fix performance issues. Sending messages...

Is it possible to have auto filters in Linq to SQL ?

Hi ! I am working on a system that the client decided to use status for the records. One of them is X for excluded. What I want to know is if it is possible to run linq queries that adds something like where status != 'X' Automatically to not show "excluded" records. Thanks ! ...

How to convert the column in order by linq

Select Year From MyTable Order By Cast( [Year] as Int ) Desc Same thing I am trying to do in the linq order by. It's not working. I have column that is defined in the data base as string (Varchar) and I need to cast/convert it to integer before I need to sort it. What should be my linq statement? Thanks in advance. ...

edmx file to an XML document

Can I connect an edmx to an xml document instead of a sql database.If so how can this be done? ...

I need to be able to separate my select statements for EF

I have about 10 calls that have the same select statement. It's more than a simple FirstOrDefault, it has some db logic inside of it. I have not seen a good way to extract this into its own method or statement. I have come close with something like this: static readonly Expression<Func<DbUser, User>> GetUser = (g) => new User { Ui...

Does LINQ to Entities expression with inner object context instance translated into sequence of SQL client-server requests?

I have ADO.NET EF expression like: db.Table1.Select( x => new { ..., count = db.Table2.Count(y => y.ForeignKey.ID == x.ID) }) Does I understand correctly it's translated into several SQL client-server requests and may be refactored for better performance? Thank you in advance! ...

How do lazily loaded POCO entities, entity framework and WCF work together?

If a project has used POCO for entities and uses entity framework and uses lazy loading then you have an "incomplete" object graph going back over the wire. So when a client uses the Entity is there some sort of proxy that will automagically load the remaining values? Do we have to create this proxy ourselves and wrap the original entity...

Linq to Entities Querying for Nullable data types

I got a scenario where we are doing soft delete on the rows in database. I want to include the rows that are not deleted. How can I achieve it using LINQ. Say from c in context.ASDSet where (c => c.DeletedFlag.HasValue && !c.DeletedFlag.Value) But I couldn't achieve the result. I want the resultant SQL to be of form: select * from...

Custom property error in linq to entities

Hi, I am using EF4 and I am getting an error with my custom property. I have 2 properties in my Application class, namely Initials and Surname. It is a partial class. I created a custom property in my Application class called Owner, and it looks like this: public partial class Application { public string Owner { get ...

Eager Loading Children for a LINQ stored procedure call

I have a special stored procedure that returns a List of Distributors from my database. I then iterate through the loop of Distributors and output the results to a web page. However, I need to load the State and the Country for each Distributor. I would rather do this one time, before the loop so that the page is faster. This is my c...

Compiled LinQ query with with expressions in functions

I would like to create a compiled query which uses reusable where predicates. An example to make this clear: ObjectContext.Employees.Where(EmployeePredicates.CustomerPredicate) EmployeePredicates is a static class with a property CustomerPredicate that looks like this: public static Expression<Func<Employee, bool>> CustomerPredicate ...

Entity Framework Code First - Eager Loading not working as expected?

I have the following Entity Framework POCO classes: public class Customer { public int Id {get;set;} public string Name {get;set;} public virtual ICollection<Order> Orders {get;set;} } public class Order { public int Id {get;set;} public int CustomerId {get;set;} public int OrderTypeId {get;set;} public v...

Entity Framework - Navigating and Including properties through collections

I've just had a massive blonde moment*, but it's highlighted an annoyance I have with Entity Framework. I have disabled lazy loading so I'm forcing myself to actually think about what data I require in order to keep the application as fast as possible. So in order to return data within a query, I need to make use of the Include method:...