linq

Is there a way to speed up this code that finds data changes in two XML files?

The following code compares two XML texts and returns a collection of data changes between them. This code works fine but needs to be as resource-friendly as possible. Is there a faster way to do this in LINQ, e.g. without creating the two collections of XElements and comparing each of their fields for differences? using System; using...

How can we optimize this linq to entity query to decrease the response time ?

IQueryable<WebEvent> mySearch = eventDC.GetBooks() .Where(p => p.Price.Any(d => d.EventDatetime.Month == fromDate.Month && d.EventDatetime.Year == fromDate.Year)) .WithGroup(groupId) .OrderBy(p => p.Price.Where(r => r.Datetime >= fromDate) .Or...

Linq Datacontext and "unit of work"

The buzword in Linq now days is "unit of work". as in "Only keep your datacontext in existence for one unit of work" then destroy it. Well I have a few questions about that. I am creating a fat client WPF application. So my data context needs to track the entire web of instantiated object available for the user on the current screen. ...

Does Enumerable.Repeat() do a deep copy ?

Hi all, If I use the following: var myList = Enumerable.Repeat(myCustomObject, 2); Will the Second element in the list be a deep copy of the first one? Note: myCustomObject can be any Object Edit: Could you also please let me know the potential use of Enumerable.Repeat when dealing with custom objets? Thanks ...

When should one care about finishing one method before start next one?

Using C# in WPF, together with LINQ to SQL and LINQ for quering my generic collections, I noticed that sometimes, when I use several methods one after another and results of the first one are needed for next function, I should care about finishing actions of first function before starting next. SomeMethod() { FirstMethod(); NextMeth...

Permissions Design

I have an application that has content that needs to be setup for permissions (i.e. member/non-member) I have roles/authentication setup just fine, that is not my issue. My question is basically asking the best way to store permissions for each object. Essentially there is "Guest" and "Member" roles, and simple "Allow" "Deny" permission...

Is there a way to fill a collection using a LINQ expression?

One of the great things about LINQ is that allows you to get information that's related to a collection without having to manually write code to iterate through the collection. Is there a way to use LINQ to populate a collection, thus avoiding the need to write a loop? For example, let's say I have the following code which works with...

Algorithm in the tag clouds (Calculating)

I have a tag list which contains a list of duplicated tags, such as "tag1", "tag1", "tag2", "tag3", "tag3" and "tag2". I want to calculate and how many tag1, tag2 and tag3 are in the list, and then add them into a new tag list such as var tagList = new List<Tag>(), it will have thousands of the tags in the list. Can anyone one help me ...

How do you find the group-wise max in LINQ?

I'm trying to solve the "group-wise max" problem in LINQ. To start, I have a database modeled using the Entity Framework with the following structure: Customer: --------- CustomerID : Int32 Name : String Order: ------- OrderID : Int32 CustomerID : Int32 Total : Decimal This gives me navigation from a Customer to her orders and an Or...

Transform LINQ IQueryable into a paged IQueryable using LINQ to NHibernate

Hi! I wanna do something like that public IQueryable GetPaged<TSource>(IQueryable<TSource> query, int startIndex, int pageSize) { return GetSession() .Linq<TSource>() .UseQuery(query) .Take(pageSize) .Skip(startIndex); } So you can put any IQuerable statement and "it become...

A clever alternative in LINQ for iterating over HashSet<string>

I've got a whitelist of URLs I'm using, inside a HashSet<string>. I'm trying to find if the url starts with any of the items in the white list (it has to be that way round). Edit: The previous example was a bit misleading and had a typo - I already have a base url like yahoo.com, the whitelist is just the path. HashSet<string> whiteLis...

linq returning IEnumerable<{Object,Object}> from a function

Hello, I wish to do something like the following in my data layer public IEnumerable<{string,int}> ListIngredients() { return from i in RecipeIngredients select new {i.Ingredient.Name, i.Quantity}; } this obviously doesnt work. c# will only let me return IEnumerable and i wish to expose the structure. ...

SqlMetal wrongly generates the return type of my stored proc (LINQ)

Hi, Hi have a stored proc that always returns a single row depending of a parameter: IF @bleh = 1 SELECT TOP 1 Xyz FROM Abc ELSE SELECT TOP 1 Def FROM Abc I must use SqlMetal to generate the DataContext but this stored procedure returns a IMultipleResults, which is an error. Instead it should return a ISingleResult... If I remov...

Most powerful and unexpected benefit of Linq in .NET OOP/D?

Since learning about Linq and gaining experience in it, I find myself leaning on it more and more. It’s changing how I think about my classes. Some of these changes were expected (ex. Using collections more) but often unexpected (ex. Getting initial data for a class as an XElement and sometimes just keeping it there, processing it lazi...

linq extension methods: Is there a way to add an OR clause to a where method

I have a statment like this: foreach (var container in modelEntities. Where(me => me.Value.ModelEntityType == (int)EntityType.Container)) Now I want to add an or clause to this where statement, however I can't seem to be able to do it. Is there a way? or do I have to do the var containers = (from me in modelEntities whe...

How can I tell LINQ to construct my entities with my own query data

I know it will sound strange but please don't mind: In C#, let's say I manually do with ADO or anything else: SELECT * FROM Member Then I want LINQ to construct my Member entities from the data I just retrieved myself from the query... Do you have an idea if it's possible? Thanks ...

asp.net LINQ vs Datatable

I have datagrid in asp.net page. Also theer are filters and search button for grid. I have following possible option for coding Apply filters for grid inside stored procedure Fetch all data for grid and apply filters + search text using LINQ Fetch all data for grid in datatable and apply filter + search text as a datatable filters. I...

Problem with LINQ in asp.net

Hi, I would like to implement LINQ IN ASP.NET for filter required data from datatable. I have doubt that what is right place. I have following options At presentation layer *.aspx.cs At our Business layer. At our Data base layer, where query for database happen which is return as a datatable to business layer. Business layer then retur...

IList - LINQ to filter and order by

I have the following test code to search a generic list: public void DoSearch(string searchTerm) { IList<MyEntity> entities = GetCollectionOfEntities(); IList<MyEntity> results = entities.Where(d => d.Description.Contains(searchTerm)).ToList(); } I want to pass an order by parameter (which would be a property of MyEntity) and of co...

How install LINQ Preview May 2006 on windows 7?

I have Visual Studio web developer Addison , Visual Basic 2005 Express Edition, Visual C# 2005 Express Edition and Visual Web Developer 2005 Express Edition installed on my system. My operative system is a Windows 7 When I start the installation of "LINQ Preview (May 2006).msi", I get the next error message: "Cannot find a valid Produc...