linq

Build XML document using Linq To XML

Given the following code: string xml = ""; //alternativley: string xml = "<people />"; XDocument xDoc = null; if (!string.IsNullOrEmpty(xml)) { xDoc = XDocument.Parse(xml); xDoc.Element("people").Add( new XElement("person", "p 1") ); } else { xDoc = new XDocum...

How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?

In my generic repository I have below method: public virtual IEnumerable<T> GetAll<T>() where T : class { using (var ctx = new DataContext()) { var table = ctx.GetTable<T>().ToList(); return table; } } T is a Linq to Sql class and I want to be able to OrderBy on a particular property (i.e. int SortOrder). S...

Call Method from Linq query.

Hello Everybody, I am using Linq query and call method Like.. oPwd = objDecryptor.DecryptIt((c.Password.ToString()) it will return null value. Means this will not working. how I Resolve this. Thanks.. var q = from s in db.User join c in db.EmailAccount on s.UserId equals c.UserId join d in db.POPSettings on c...

What Should I know to underestand LINQ better?

As LINQ is a good query language in dot net and everyone should be able to work with it. What are the necessary abilities which a programmer should have, before start learning LINQ. And after that, What should he know about LINQ? (important tips) ...

Getting error in MVC Proj while writing Lambda Expression

hi, i am creating a sample movie (MVC) application. I was getting fine with Viewing and Creating a new record, but when i wrote the code to get the details of a particular record i met with the following error: Unable to cast objec`t of type 'System.Data.Objects.ObjectQuery`1[MovieApp.Models.Movie]' to type 'MovieApp.Model`s.Movie'. ...

How to Get A Joined Query to List Object

I have a dynamic sql query which contains more than one table joined. Normally I get this query to a datatable and use it. For now I want to get result of this query to a list object. Does anyone help me about this case? ...

Help with a algorithm in linq to resolve a query

I have been some time thinking how to resolve this problem, but out of ideas i prefer expose it for help. I have 2 tables (linq to sql) A and B, A have a many relation with B, so A have a property EntitySet of B A have the following properties: CreateDate (Datetime) ModificateDate (Datetime) Bs (EntitySet<B>) B have the follow...

VB.Net Linq Datatable Exists

I would like to use Linq instead of below function : Friend Function IsCollectionInTable2(ByVal apps As DataTable, ByVal collectionId As String) As Boolean For Each row As DataRow In apps.Rows If row("CollectionId").ToString = collectionId Then Return True Next Return False End Function The best I can do is below: ...

Is it possible to update old database from dbml file ? (C#, .Net 4, Linq, SQL Server)

Hi all, I began recently a new job, a very interesting project (C#,.Net 4, Linq, VS 2010 and SQL Server). And immediately I got a very exciting challenge: I must implement either a new tool or integrate the logic when program start, or whatever, but what must happen is the following: the customers have previous application and database ...

ToList()-- Does it Create a New List?

Let's say I have a class public class MyObject { public int SimpleInt{get;set;} } And I have a List<MyObject>, and I ToList() it and then change one of the SimpleInt, will my change be propagated back to the original list. In other words, what would be the output of the following method? public void RunChangeList() { var objs = ...

How to Group and Order in a LINQ Query.

I would like to group & order by in a query builder expression. The following query gets me close to what i want but the order by does not appear to be working. what i have is an object that has unique ids but some will have a common versionId. I would like to get the last edited item of the same versionId. So only one item per versi...

VB.NET LINQ Result Set Manipulation.

I have a table that looks like this: ID / Description / textValue / dateValue / timeValue / Type 1 / FRRSD / NULL / 2010-04-16 00:00:00.000 / NULL / classdates Now I've got a LINQ command to pull only the rows where the type is classdates from this table: Dim dbGetRegisterDates As New dcConfigDataContext Dim getDates = ...

xml Class to substitute ini files

I am learning Windows Forms in C#.NET 2008 and i want to build a class to work with SIMPLE xml files (config file like INI files), but i just need a simple class (open, getvalue, setvalue, creategroup, save and close functions), to substitute of ini files. I already did something and it is working but I am having trouble when I need to ...

Supported Linq for WCF Data Services

I'm looking for the full list of supported linq extension methods that are compatible with WCF Data Services. By trial and error I've found First( Func ) and Single( Func ) aren't supported, any others? This gives me a pretty good idea of whats supported, I just don't know whats actually translated via the IQueryProvider. ...

How do I check if a SQL Server 2005 TEXT column is not null or empty using LINQ To Entities?

Hi there guys I'm new to LINQ and I'm trying to check whether a TEXT column is null or empty (as String.IsNullOrEmpty). from c in ... ... select new { c.Id, HasBio = !String.IsNullOrEmpty(c.bio) } Trying to use the above query produces an SqlException: Argument data type text is invalid for ar...

Possible to assign a data type to an anonymous type's members in a linq query?

If I have a linq query that creates the anonymous type below: select new { lf.id, lf.name, lf.desc, plf.childId }; Is it possible to assign a specific type to one of the members? ...

sql to xml using linq - nested collections

I have a table of data that looks something like this. name, hour, price1, price2, price3, price4, price5 fred, 3, 12.5, 13.5, 14, 15, 16 dave, 6, 8, 12, 18, 20.2, 25 fred, 6, 10, 11, 14, 15, 19.7 This table needs to be output to an xml file that looks like this. <timeCost> <person name="fred"> <time hour="5"> <cost price...

Which LINQ query is more effective?

I have a huge IEnumerable(suppose the name is myItems), which way is more effective? Solution 1: Filter it first then ForEach. Array.ForEach(myItems.Where(FILTER-IT-HERE).ToArray(),MY-ACTION); Solution 2: Do RETURN in MY-ACTION if the item is not up to the mustard. Array.ForEach(myItems.ToArray(),MY-ACTION-WITH-FILTER); Is one of ...

NHibernate LINQ query throws error "Could not resolve property"

I'm testing out using LINQ with NHibernate but have run into some problems with resolving string.length. I have the following public class DC_Control { public virtual int ID { get; private set; } public virtual string Name { get; set; } public virtual bool IsEnabled { get; set; } public virtual string Url { get; set; } ...

Select Query in Linq

Hi, I am very new in Linq, I want to select two coloum of table. so tell me how can i write query for that . I want to fill dropdown list . Thanks Manoj ...