C# - LINQ To SQL To Query Parent And Count Childs In Hierarchy?

Dec 8, 2010

I'd take both C# and VB.NET suggestion.I'm using LINQ to query data. I'm trying to query the parent and count the child tags.Here's my Tags table column:

TagId (int primary)
TagName
ParentId (int Allow NULL referred to TagId column)

Here's some sample data:

[Code]...

View 3 Replies


ADVERTISEMENT

LINQ - Query Children Object If Parent Count Is = 1

Apr 17, 2012

I have a the following Class structure. Company > List(of Departments) > List(of Employees) I want to Query a Company to find out if it has a department of the following name and a Employee in that department with the following ID! How could I query this. The way I have the code it expect to return one department so I have it doing

[Code]...

View 2 Replies

Hide All MDI Childs From Parent?

Dec 2, 2010

Been searching the web for about an hour now and not having a lot of luck. Got my MDI Parent with some buttons on and one of the buttons I want to hide all open MDI Children forms but I don't want to close them.

View 2 Replies

MDI Parent Save The Open Childs At Shutdown?

Jan 3, 2009

I have an MDI web browser and it would be handy if it could save the open MDI childs at shut-down so that the next time the user would open the web browser the MDI childs would be still there...

Is that even possible?Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]...

View 5 Replies

Forms :: Detecting Open MDI Childs When MDI Parent Is Closed

Dec 16, 2010

I'm new to VB 2010 but have be using VB6 for many years.I'm currently stuck trying to store the state of open MDI childs at the moment the MDI parent is closed. Clicking the parent upper right close button appears to close all open MDI childs before running the parent 'Closing' or 'Disposed' events.I am therefore unable to detect which MDI childs are open and cannot restore them next time the application is run.Is there any other event for the MDI parent I can detect the start of the closing process before the children are closed?

View 2 Replies

Get The Count From A Query Expression In Linq?

Jan 25, 2012

What I have right now is this:

Dim users = From users In tempTable _
Distinct Select users.Item("s_userid")
Dim usersCount As Integer = users.Count

But I pretty sure I shouldn't have to do that. I should be able to get the count in/from that first linq query.

View 2 Replies

Getting All The Parent Hierarchy Until Reaching A Certain Type?

Feb 3, 2009

I could put a Textbox in a Panel then that panel is placed in a TabPage, how do I go out going through the hierarchy of the Textbox parent until reaching the TabPage? My purpose for this is if I want to focus on a Textbox then of course I would have to also select the TabPage where it is located, is there an easier way than what I am planning to do?

View 3 Replies

Sql - Group By Having And Count As LINQ Query With Multiply Nested Tables?

Feb 28, 2012

I have the following SQL query to return all Customers who have no OrderLines with no Parts assigned - i.e. I only want the customers within which every order line of every order has no parts assigned - (in the actual problem I am dealing with a different domain but have translated to customers/orders to illustrate the problem)

SELECT c.Customer_PK
FROM Customers c
INNER JOIN Orders o[code].....

This works but generates less than optimal SQL - it is doing a subquery for Count on each row of the customers query rather than using Group By and Having. I tried making the LINQ Group By syntax work but it kept putting the filter as a WHERE not a HAVING clause.Edit in response to Answers below: I am accepting JamieSee's answer as it addresses the stated problem, even though it does not produce the GROUP BY HAVING query I originally had.I am a VB developer so I have had a crack translating your code to VB, this is the closest I got to but it does not quite produce the desired output:

Dim qry = From c In context.Customers
Group Join o In context.Orders On c.Customer_PK Equals o.Customer_FK
Into joinedOrders = Group[cod].....

The problem I had is that I have to push "jl" into the Group By "Key" so I can reference it from the Where clause, otherwise the compiler cannot see that variable or any of the other variables appearing before the Group By clause.With the filter as specified I get all customers where at least one order has lines with no parts rather than only customers with no parts in any order.

View 3 Replies

ASP.NET MVC - Linq Query With Count Returns Anonymous Type - How To Display In View

Sep 29, 2011

So I'm writing a query as follows:

Dim assSummary = From a In db.Assignments
Join ur In db.UserRegions
On a.Origin.ID Equals ur.Region.ID

[code]....

In the controller I can return the data easily as follows:

For Each c In assSummary
MsgBox(c.Description & " " & c.AssCount)
Next

If I pass the object through to the view using Viewdata("assSummary") = assSummary, how do I display the data? Every method I've tried results in messages about 'VB$AnonymousType_7(Of Integer,String) and I don't know how to retrieve the data from the anonymous type.

View 1 Replies

Filter Parent / Child Table In Linq Query Based On Entities In Child Table?

Jul 9, 2010

I have a table (Projects) which is linked to projectVersions on projectID..projectVersions contains several columns on which I'd like to filter a returned project (and associated projectVersions) list. For example there is a "capacity" column and a "country" column. I am doing a filtered list of projects on one page and I'd like to include all projects where any one of the associated projectVersions has a capacity of 750ml and a country of "France" for example.It may be that a particular parameter is not set and so I pass a zero to indicate not to filter on that.I guess this needs some kind of subquery as when I try and do something like this: [code] it doesn't work as the "xxx" bit, being one-to-many, expects me to specify an item to get at the entities within and yet I want to query where ANY of the associated versions match one of the criteria.

View 1 Replies

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

VS 2010 Count Childnodes Of Parent (Treeview)?

Sep 26, 2010

how to count the Childnodes of the Parent? I have several Parents, but I need to count only the children of a specific Parent. Means not all the childnodes. I know that I need to use the .count.

View 17 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Asp.net - Complex Linq Query - Add A .Where() Or .Any() Predicate To Reduce Query Complexity (in VB)?

Sep 14, 2010

I have to join two main tables, and I need to filter the results by elements in an ASP.NET web form. These filters are created on the fly so I have to use a lot of where extensions to filter the query. I want to execute the query with as optimized SQL as possible.

I am first doing a simple join between TW_Sites and TW_Investigators. Then there are two sub-tables that are involved. TW_InvestigatorToArea and TW_InvestigatorToDisease. While most of the where clauses are working fine, I have found a performance issue that won't be an issue right now, but will be an issue as the table gets bigger.

The arrays DiseaseCategories and DiseaseAreas would be the results of a CheckBoxList result.

Protected Sub LoadResults()
'Get Dictionary of Filters
Dim FilterDictionary As OrderedDictionary = Session.Item("InvestigatorFilterDictionary")
' Initialize LinqToSql

[code]....

View 2 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

LINQ XML Get Parent Element

Oct 28, 2010

Using the XML elements below, I am trying to locate all table elements where they have a column@Name equal to a specific item such as "email" and return the Database@Location and Table@Name. My LINQ statement returns the proper table@name but for each element found returns the first database@Location for both. So my question is, how can I search for a column@Name and return the proper Database@Location and Table@Name [Code]

View 1 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

LINQ To SQL - Add In Row_Number To A LINQ To SQL Query?

Aug 31, 2011

How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?

[Code]...

I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.

View 1 Replies

Aggregating Parent/child Tables Using Linq To SQL?

Sep 18, 2009

I'm having a nightmare with LINQ. I've got a table of Projects, and each project has many InvoiceHeaders. The Invoice header had a field AmountNet - the value of the invoice.

I want to retrive, for arguments sake, all of the fields from Projects, with the count of invoice headers and the sum of AmountNet. I.e. list of my projects, how many invoices I've raised and the value.

Doesn't sound hard does it.... well, I've just spent the best part of two hours charging through Google and SO to find a solution.

[Code]...

View 1 Replies

C# - LINQ - Select All In Parent-child Heirarchy

Mar 12, 2012

I was wondering if there is a neat way do to this, that DOESN'T use any kind of while loop or similar, preferably that would run against Linq to Entities as a single SQL round-trip, and also against Linq To Objects. I have an entity - Forum - that has a parent-child relationship going on. That is, a Forum may (or in the case of the top level, may not) have a ParentForum, and may have many ChildForums. A Forum then contains many Posts.

What I'm after here is a way to get all the Posts from a tree of Forums - i.e. the Forum in question, and all it's children, grandchildren etc. I don't know in advance how many sub-levels the Forum in question may have. (Note - I know this example isn't necessarily a valuble use case, but the Forum object model one is one that is familar to most people, and so serves as a generic and accessible premise rather than my actual domain model.)

View 2 Replies

C# - LINQ To SQL Count Table With Relationship

Jun 17, 2011

C# or VB.NET is fine. I'd like to count number of people for each country from the following tables with LINQ to SQL I have two tables, one is Countries and other is People. It's one to many relatoionship from Countries to People. ountries table column:CountryId,CountryName People:PeopleId,FullName,CountryId (a primary key from Country table and allowed null) I want to count how many people each country has and get something like the following result that shows only the country that has people. Because there are some countries that have no people in the People table.

[Code]...

View 2 Replies

Linq Group Count Items?

Dec 5, 2011

I have this linq to entity

From r In ReceiptRepository.Fetch
Where
r.RECEIPTDATE >= ReportStartDate And

[Code]....

This is working fine, except the count property, it is just giving the number of group count. I don't know how to find out each Tender Count

View 1 Replies

LINQ To SQL Using GROUP BY And COUNT(DISTINCT)

Jan 15, 2009

I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr)
from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query

[Code]...

View 5 Replies

Linq-to-sql Speed When Getting Table Count?

Mar 31, 2012

Dim mydata = (From c In dc.Table Select New With {c.ID}).Count
any faster than this:
Dim mydata = (From c In dc.Table Select c).Count

[code].....

View 1 Replies

Using Linq Count Function With Datatable?

Aug 2, 2011

I write the code below. I want to make short using linq count.

Dim query0 = From obj In dtAginglist _
Where (obj.Field(Of String)("CurrentStatus") = "Open" Or obj.Field(Of String)("CurrentStatus") = "Acknowledge") _

[Code]....

I try to use code below but it dosen't work with if source is datatable.

Dim orderCounts = From c In customers New With { _
c.CustomerID, Key .OrderCount = c.Orders.Count() }

View 1 Replies

LINQ To Objects - GrandParent / Parent And Children List

Feb 3, 2010

Basically, I am trying to write a LINQ to Objects statement where the relationship is a grandparent, parent, child relationship. (You could also call it a Master Detail relationship.)

In Legacy code here is a simplified version what I am trying to accomplish.
Dim coverages As New List(Of Coverage)
Dim coverage As Coverage
For Each rl In oClaimsPolicy.RiskLocations
coverage = New Coverage
coverage.Level = "Location"
[Code] .....

If is it not clear one Location can have many Items and one Item can have many Coverages. I basically want to list the items and show the relationship between grandparent (Location), parent (Item) and child (Coverage).

View 5 Replies

VS 2008 Linq Possible To Use Query In Another Query?

Apr 16, 2011

I was wandering is it possible to use a query within another query below is the code I am trying to use.

Public Function GetInventByComp(ByVal CompID As String) Using DC As New DataClassDataContext
'need to get company id's based off names? thats bad should be name from Id need to rethink this
Dim invent = (From C In DC.Inventors_Companies _
Where C.CompID = CompID _
Select C.InventorID).ToString

[Code]...

I was trying to us multiple values in a string like "1, 3, 5" but I can't seem to get that working either so I am trying to use just a single value now. Can anyone help me? "Yes I am new to this"

View 5 Replies

LINQ + Find Count Of Non-null Values

Apr 2, 2010

I have a table with the below structure.

ID VALUE
1 3.2
2 NULL
4 NULL
5 NULL
7 NULL
10 1.8
11 NULL
12 3.2
15 4.7
17 NULL
22 NULL
24 NULL
25 NULL
27 NULL
28 7

I would like to get the max count of consecutive null values in the table.

View 3 Replies

Linq Distinct Count Multiple Fields

Mar 24, 2012

I have a Table:

[Code]...

I'm trying by LINQ-query (VB.NET) to return a count for distinct value of Objects, Stuffs and Colours for every Room:

[Code]...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved