linq

Generating a LINQ query using Expression Trees

Update Thanks to Marc's help the AlphaPagedList class is now available on CodePlex if anyone is interested Original I'm trying to create an expression tree to return elements that start with a given charecter. IList<char> chars = new List<char>{'a','b'}; IQueryable<Dept>Depts.Where(x=> chars.Contains(x.DeptName[0])); I want this to...

WPF, Linq to SQL, C# > How to Populate and Save A Combobox

Pulling my hair out. I've got a table 'Belts' with columns 'BeltID' and 'BeltColor'. I've got a Linq to SQL generated class, and am trying to populate a combobox and it's only partially working. Here's what I've got so far: private void Window_Loaded(object sender, RoutedEventArgs e) { using (DojoDataClassesDataContext conn = new Do...

Linq to Entities strange deploying behavior.

Hi I started building apps with this technology and I am facing a weird problem... on some machines I need to add theese lines to the app.config to get to work: <system.data> <DbProviderFactories> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MyS...

LINQ query for tag system: Matching any of several tags?

I am just getting started with LINQ. I am creating an Entity Framework app that uses the canonical Post and Tag model. A Post contains an ID, Text, and Tags, and a Tag contains an ID, a Name, and Posts. A previous thread on StackOverflow showed me how to query for a Post that matches all Tag objects (A and B and C) in a search list. Bu...

Zipping Rx IObservable with infinite number set

I have a IObservable [named rows in the sample below] from Reactive extensions framework and I want to add index numbers to each object it observes. I've tried to implement this using Zip function: rows.Zip(Enumerable.Range(1, int.MaxValue), (row, index) => new { Row = row, Index = index }) .Subscribe(a => ProcessRow(a.Row, a....

How do I add two lists in Linq so addedList[x] = listOne[x] + listTwo[x]?

I want to add two lists of a numeric type such that addedList[x] = listOne[x] + listTwo[x] The output of the list needs to be a Generic.IEnumerable that I can use in future linq queries. While I was able to do it using the code below, I can't help but feel like there must be a better way. Any ideas? List<int> firstList = new List<in...

GetRolesForUser tries to get Roles on old username?

I have a section on a page where a user can change their username. This is basically the code for that: user.UserName = txtNewUserName.Text; user.Save(); user is a class in my dbml and Save calls SubmitChanges on the data context. The name is changed in the database, so when it calls the following method, it fails because it is tryi...

LINQ Guid toString()

Hi this seems like it should work, from something in collectionofsomestuff select new SelectListItem(){Text = something.Name, Value = something.SomeGuid.ToString(), Selected = false}; When I try to do this it doesn't work give me error LINQ to Entities does not recognize the method 'System.String ToString()' method, and thi...

Switching from LinqToXYZ to LinqToObjects

In answering this question, it got me thinking... I often use this pattern: collectionofsomestuff //here it's LinqToEntities .Select(something=>new{something.Name,something.SomeGuid}) .ToArray() //From here on it's LinqToObjects .Select(s=>new SelectListItem() { Text = s.Name, Value = s.Some...

LINQ to group objects according to timestamp

I have a serial of object defined as: public class Foo { public DateTime Time {get;set;} } now I want to group objects(IEnumerable<Foo>) according to the time, e.g. I want to group them according to hour or day or month. for example (group into hour): group 1(13:00-14:00) : foo1, foo2, foo3 group 2(14:00-15:00): foo4, foo...

Pivot Table in LINQ in VB.NET

Hi, I'm looking for doing a Pivot Table query in vb.net. I've found a lot of code in c# but not in VB.Net and i don't understand how to convert c# to VB. Can you help me? Thanks Ju ...

LINQ2SQL and SQL Server 2000

Good day! I have used LINQ2SQL with SQL Server 2005, but now I need to use it with SQL Server 2000. I have found only article on MSDN that tells about Skip() and Take() oddities on SQL Server 2000 (that's because it lacks ROW_NUMBER(), I suppose) and nothing more. Anyway, does anybody have experience with LINQ2SQL and SQL Server 2000 c...

How to get values after dictionary sorting by values with linq

hey, I've a dictionary, which i sorted by value with linq, how can i get those sorted value from the sorted result i get that's what i did so far Dictionary<char, int> lettersAcurr = new Dictionary<char, int>();//sort by int value var sortedDict = (from entry in lettersAcurr orderby entry.Value descending select entry); during the ...

how to delete all records from database using linq

how to delete all records from database using linq.i want to delete all records from the database using linq.i am using MVC.so please tell me the code to delete all records using repository. reply me soon thanks samir ...

Getting an XML node using LINQ

Somehow, using linq I can't test it with this CUF field in the beginning: <NFe> <infNFe versao="1.0" Id="NFe0000000000"> <ide> <cUF>35</cUF> <!--...--> </ide> </infNFe> </NFe> With the following code: XDocument document = XDocument.Load(@"c:\nota.xml"); var query = from NF...

count on LINQ union

I'm having this link statement: List<UserGroup> domains = UserRepository.Instance.UserIsAdminOf(currentUser.User_ID); query = (from doc in _db.Repository<Document>() join uug in _db.Repository<User_UserGroup>() on doc.DocumentFrom equals uug.User_ID where domains.Contains(uug.UserGroup) select doc) .Union(fro...

Deferred execution and eager evaluation

Hi Could you please give me an example for Deferred execution with eager evaluation in C#? I read from MSDN that deferred execution in LINQ can be implemented either with lazy or eager evaluation...i could find examples in the internet for Deferred execution with lazy evaluation ,however i could not find any example for Deferred executi...

LEFT OUTER JOIN in Linq - How to Force

I have a LEFT OUTER OUTER join in LINQ that is combining with the outer join condition and not providing the desired results. It is basically limiting my LEFT side result with this combination. Here is the LINQ and resulting SQL. What I'd like is for "AND ([t2].[EligEnd] = @p0" in the LINQ query to not bew part of the join condition b...

Problem with LINQ Where Clause

var results = from formNumber in context.DetailTM join c in context.ClaimPeriodTM on formNumber.ClaimPeriod equals c.Cid where formNumber.FormNumber.StartsWith(fNumber) && formNumber.RegistrationNumber != registrationNumber select new { RegNo = formNumber.RegistrationNumber, CP = c.ClaimPeriod, ...

Enumerate Class Properties in C#

I have a class Similar to this public class Model { public TimeSpan Time1 {get; set;} public TimeSpan Time2 { get; set; } public TimeSpan Time3 { get; set; } public TimeSpan Time4 { get; set; } } Now Let's Imagine I have to populate the times during runtime and then Figure out the time remaining between Time 1 and T...