linq

Need to populate a collection's sub-collection when selecting new

Everything in my Linq query is working properly except for the area where I'm trying to populate a sub-collection with data. (Anything referencing ChannelInfo). ChannelInfo does appear in Intellisense, so it is recognized as a property of the new OfferType. The right side of my setters for ChannelInfo are also recognized and accessibl...

[SQL/Linq to SQL] How do I group/aggregate but return fields other than the aggregation field?

I have two tables, Tasks and TaskMilestones. I want a query to return the most recent past milestone and the nearest future TaskMilestone for each Task. I'm working with C#/LINQ-to-SQL. How do I go about this? Task columns: Id, TaskName TaskMilestones columns: Id, TaskId, MilestoneName, MilestoneDate I want a return table with rows...

How to Join in LINQ using Lambda expressions and get the result in DTO?

Hi I have a query as - var query=from e in DataContext.Employees join d in DataContext.Dept on e.DeptId equals d.Id join o in DataContext.OtherInfo on e.Id equals o.EmployeeId where e.EmployeeId==4 select new Employee_Dept//DTO { EmployeeName=e.Name,...

Help with sql to linq conversion

Could somebody assist me in converting a sql query into LINQ, i'm pretty handy with linq but this is a bit much and i can't download linqpad here! select t.*, l.* from email_templates t left join (select id as email_id, sent_at, sent_by from email_log where id = (sel...

Doing Recursive Function using LINQ and Delegates

I was under the impression that the only difference between Func and Action is that the former has to have a return value.So I thought you can call a recursive linq from either a Func or Action. I am new to C# and I am just experimenting and curious. So I tried the following to recursively print the nested types within a Type. Type t ...

Joining Xs, Ys into Points with Linq

I seem to be a bit stuck on this, but my experience in Linq is not great. Basically, I have something like this code: public class Point { public int X { get; set; } public int Y { get; set; } } public class B { public List<Point> Points { get; set; } public B(IEnumerable<int> Xs, IEnumerable<int> Ys) { // H...

take out foreach using linq

Is there a way to take out the foreach in the following code in linq yet produce the same output? DropDownList ddl = new DropDownList(); foreach (DataRow row in ds.Tables[0].Rows) { if ((byte)row["ListTypeID"] == 0) { item = new ListItem(row["ListText"].ToString(), string.Format("{0}:{1}", row["Li...

Wrapping LINQ query to a Repeater

Hi, At the moment I have ResultsCollection = List<MyDataStructure>; which is then analysed with LINQ using something like: var OrderedData = from tc in ResultsCollection ... select new { myLink = g.Key, Count = g.Count(), First = g.First() }; At the moment I have a Repeater that is deifned using: myRepeater.DataSource = ResultsCol...

WCF Linq2SQL Not Returning "Parent" objects

I have a WCF Service which retreives data via Linq2SQL. I am getting all the child records, just not the related parent records i.e Customer record has related Orders, and there is a status on the customer. I am getting the customer and the orders, but I cannot get the status record to get the status description using (MyDataContext c...

Designing an append-only data access layer with LINQ to SQL

I have an application in mind which dicates database tables be append-only; that is, I can only insert data into the database but never update or delete it. I would like to use LINQ to SQL to build this. Since tables are append-only but I still need to be able to "delete" data, my thought is that each table Foo needs to have a correspo...

is it possible to have a conditional field in an anonymous type

i have some code that looks like this and creates a list from an existing collection var items = items.ConvertAll(r => new { description = FormatDescription(r), start = r.Milestone.HasValue ? r.Milestone.Value.ToString("yyyy-MM-ddTHH:mm:ssZ") : DateTime.Today.ToString("yyyy-MM-ddTHH:mm:ssZ"),...

How do I make asynchronous calls to sprocs using the Entity Framework in .NET?

The only way that I know of to make an async call using Linq to SQL is to compose an IQueryable and then ask the data context for the equivalent SqlCommand using GetCommand, which provides the BeginExecuteReader method. This approach didn't work for stored procedures and required some hackery to essentially use reflection to generate the...

LINQ to SQL cross apply

I would like to create a query with a cross apply into a user defined table value funtion in LINQ. The SQL would be really rather simple as below: SELECT * FROM MyTable mt CROSS APPLY MyTVF(mt.id) This post gives an example of a LINQ query that results in generated sql that contains both a cross apply and an outer apply but only for ...

How to get first level of children by LINQ

I have such XMl <root> <list> <list> <topic></topic> <topic></topic> </list> <topic></topic> <topic></topic> </list> <topic></topic> <topic></topic> <topic></topic> </root> I need to get the first level of children: <list></list> <topic></topic> <topic></topi...

Is there a general method to check whether a property define supported by a Linq provider, especially OData?

I successfully ran the following statement with the NorthWind.sdf in LinqPad: from s in Shippers select new { s.ShipperID, s.CompanyName, Count=s.ShipViaOrders.Count() } At the same time , I failed to run a similar statement with the Odata Service (http://services.odata.org/northwind/northwind.svc) in Linq...

Aggregate on dictionary question

I am using ASP.NET MVC2 and I would like to make up a url based on the current one in the address bar inside a HtmlHelper extension. So far I have this: url = helper.ViewContext.RequestContext.RouteData.Values .Aggregate<KeyValuePair<String, Object>>((w, next) => w + next); But that does not compile. Anyone has a good idea on h...

AD0.NET Entity Framework 4.0 or Linq-to-SQL.

hello, I am developing a application with asp.net 4.0. My site will be a heavy like more then hundreds of user will be online at a time and lots of content will be there. I have checked both ado.net entity framework 4.0 and Linq-To-SQL with Microsoft.NET Framework 4.0 both are having great improvement over there. I am confused that whic...

Book to learn LINQ to use in WPF

Hi All, I am new to wpf and Linq. I want to learn data binding in wpf using linq. Which book i can prefer to learn Linq. Geetha. ...

IEqualityComparer exception

Hi, I am using Entity Framework 4.0 and trying to use the "Contains" function of one the object sets in my context object. to do so i coded a Comparer class: public class RatingInfoComparer : IEqualityComparer<RatingInfo> { public bool Equals(RatingInfo x, RatingInfo y) { var a = new {x.Pl...

LINQ How to search data from large XML file?

Hi I have an xml file with about 500 mb and i'm using LINQ with c# to query that file, but it's very slow, because it loads everything into memory. Is there anyway that i can query that file without loading all into memory? Thanks ...