linq

Can you reuse a LINQ datacontext in an ASP.NET MVC application with strongly typed views

Hi, I am somewhat confused on how to properly use LINQ in combination with an ASP.NET MVC strongly typed view. My situation is as followed. 1) I retrieve a single object through LINQ 2) I pass this LINQ object to a strongly typed view. (edit form) 3) The user submits the form and the controller receives the LINQ object. So my questi...

SQL Linq Question

I have the following working TSQL query in ms SQL 2008 SELECT Date, COUNT(click) AS clicks, COUNT(sale) AS sales, count(lead) as leads FROM ( SELECT ClickDate as date ,ID AS click ,CAST(NULL AS int) AS sale , CAST(null as int) as lead FROM clicks UNION ALL SELECT Date,null, ID ,NULL FROM sales UNION ALL SELECT Date,...

How can i use generic class to write useful codes via linq?

i want to use generic class to shorter my codes because 1) GetMaintData(int taskID) RelTypeId and RefMaintenance 2) GetAliSpReqs(int taskID) RelTypeId and RefAliSpReq if you look below method you can see only TypeId and Ref data. i think that i can write new clear codes via generic class like that: http://www.thereforesystems.com/dyn...

How to AspxMenu fill from xml file

On my page I have two AspxMenu.Click on Master Menu correspondent value will show on Child menu XML syntax: <Demo> <ClientCompanyId CompanyId="1"> <MyMenu> <module Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False"> <menu Text="Forms" MID="1-1" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm...

How to use linq to object to hide or show some control in asp.net page

I am creating a function to hide all the gridview controls except the control whose name is being passed in the function. Here this.Controls referes to controls present in the page (At compilation error is thrown although). I want to fetch all the controls of type GridView with Name property not equal to the one passed in the funtion. ...

VB.NET using LINQ to transpose an ObservableCollection

I have a custom item class (basically two string values with associated properties), as below: Public Class itmDataDetails Private _strDataName As String Private _strDataValue As String Public Property strDataName() As String Get Return _strDataName End Get Set(ByVal value As String) ...

Selecting a XElement from a XDocument

Hey all I really didn't want to ask for help as I know I'll eventually figure it out, but I've spent too much time, if the document had parent tags or a better structure, it would be a piece of cake. Sadly I'm downloading the document, and I just can't figure out how to get the data. I've tried a a few linq queries and a foreach using ...

Linq.Dyanmic GroupJoin Implementation

I am working on create an Extension Method in the Linq.Dynamic project for GroupJoin. But, for some reason it will not run. The signatures seem to match. public static IQueryable GroupJoin(this IQueryable outer, IEnumerable inner, string outerSelector, string innerSelector, string resultsSelector, params object[] values) { i...

Adding only new items from one list to another

Hello... I have two lists: List<string> _list1; List<string> _list2; I need add all _list2 different items on _list1... How can I do that using LINQ? Thanks ...

LINQ query on a list of Object[] arrays

I have a list of Object arrays (List) That I am going to pass into a DLL function to apply PDF controls. The first index of each object is supposed to identify what the control will be. I was wondering if there is some way to query my list of objects to get a count of each of the identifying objects and cast it to an int? Here is a examp...

Can't get Left JOIN linq query to work!

I've been looking at the following post and trying to apply it to mine but with no luck: http://stackoverflow.com/questions/525194/linq-inner-join-vs-left-join I have the query below that returns 0 records everytime I run it: var tasks = from tt in d.luProjectTaskTypes join cbt in d.CostByTasks ...

Recursive Reflection of property values with LINQ?

I have a predicate builder that accepts a SearchInfo Class. For most cases this works great, but has problems if a user specifies a query on a property that has a deep object graph. For example, a list of possible properties: var names = new[] { "Action.Strategy.Objective.Goal.Identifier", "Action.Strategy.Objective.Identifier", "Actio...

Trouble converting a bit of TSQL to LINQ to Entities

Sorry about the vague title, not sure what verbage I should be using. I have a query similar to this (re-worked to save space): SELECT * FROM Publishers p INNER JOIN Authors a ON p.AuthorID = a.AuthorID INNER JOIN Books b ON a.BookID = b.BookID WHERE p.PublisherName = 'Foo' ORDER BY b.PublicationD...

Problem with LINQ, anonymous types, and closures

I have a piece of code that filters a list using LINQ, creates a list of instances of an anonymous type, and assigns an event handler to each instance: // Select every linear expression and create a menu item from it var items = from expr in expressionList.Expressions where expr.Type == ExpressionType.Linear let ...

If else condition in LINQ to XML query in c#

Hi, this is xml let say: <.Sections> <.SECTION ID ="4" NAME="GetStudents" CONTROL-TYPE="Button" LINK="WebForm2.aspx"> </SECTION> <.SECTION ID="5" NAME="SelectStudent" CONTROL-TYPE="Drowpdown" METHOD ="selectList_MethodName"> </SECTION> Observe this xml, I am generating the UI controls base on "CONTROL-TYPE" Att...

Optimization: How should i Optimize the Linq Concat of Collections? C#

is there any way i can Optimize this: public static IEnumerable<IEnumerable<int>> GenerateCombinedPatterns (IEnumerable<IEnumerable<int>> patterns1, IEnumerable<IEnumerable<int>> patterns2) { return patterns1 .Join(patterns2, p1key => 1, p2key => 1, (p1, p2) => p1.Concat(p2)) .Where(r => r.Sum() <= sto...

Select only few columns in LINQ query

I have the following query var xyz = from a in prod.Categories where a.CatName.EndsWith("A") select a; However all the columns are returned in this case. How do i rewrite query so that only few columns are returned like a.CatName, a.CatID, a.CatQty and so on. ...

What's your favourite linq method or 'trick'

Hi All, I know it's a highly subjective issue (and one that may well see a flurry of 'close it' votes), hence pointing it at the CW and adding the disclaimer. Anyway, I've been working thro a project in asp.net mvc using subsonic and was suddenly (again) struck with the elegence and 'ruggedness' of the linq implementation that lies on...

Ria services with silverlight has a Nhibernate Linq error with query resultlimit when paging

Hi I am having trouble with using NHibernate's Linq querying functionality when trying to page data in a silverlight application. I have a DomainService with a method like: [Query(ResultLimit = 50)] public IQueryable<Category> GetCategories() { return _Session.Linq<Category>(); } In the silverlight app, I am trying to page fo...

Using LINQ to convert a list to a CSV string

Hi, I have a list of integers and I want to be able to convert this to a string where each number is separated by a comma. So far example if my list was: 1 2 3 4 5 My expected output would be: 1, 2, 3, 4, 5 Is this possible using LINQ? Thanks ...