C# - Get The Count From IQueryable?

Mar 27, 2011

I am implementing paging in my GridView. From this article, I need two methods:

public IQueryable BindEmployees(int startRowIndex, int maximumRows)
{
EmployeeInfoDataContext dbEmp = new EmployeeInfoDataContext();
var query = from emp in dbEmp.Employees
join dept in dbEmp.Departments
on emp.DeptID equals dept.DeptID
select new
{
EmpID = emp.EmpID,
EmpName = emp.EmpName,
Age = emp.Age,
Address = emp.Address,
DeptName = dept.DepartmentName
};
return query.Skip(startRowIndex).Take(maximumRows);
}

And

public int GetEmployeeCount()
{
// How can I not repeat the logic above to get the count?
}

How can I get the value of the second method GetEmployeeCount from the first method BindEmployees ? I mean without repeating the logic (the query)?

View 3 Replies


Similar Messages:

Forms Data Controls :: GridView_RowUpdated Event The E.OldValue.count E.NewValue.Count

Jun 4, 2010

In the GridView_RowUpdated event the e.OldValues.count <> e.NewValues.Count. 1 out of 5 columns has been converted to a template field.

View 9 Replies

Forms Data Controls :: Gridview Row Count / How To Get A Count Of The Number Of Rows That Are Returned

Dec 17, 2010

When a user submits the query to SQL when clicking a button I need to get a count of the number of rows that are returned. Which event does the gridview.count code need to be place in?

Right now I have it in the btn_click event, but in order to get it to count the rows you have to hit the button twice since the query is not returned yet. Here is my code.

[Code]....

View 1 Replies

Data Controls :: Display Total Row Count And Count Of Specific Types In Label In GridView

Oct 5, 2012

I HAVE A GRID VIEW IN asp.net + VB Code. There is a drop down list and the selected data is displayed in web page. I placed a label in web page and code behind i used following code.

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
Label1.Text = GridView1.Rows.Count.ToString()
Dim ONYO As Integer = 0
Dim DONE As Integer = 0
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(0).Text = "ON YO" Then

[Code] .....

View 1 Replies

Applying Like Filter To An IQueryable?

Oct 7, 2010

I'm trying to write a custom filter for Dynamic data that will allow me to run like type queries on entity columns. For example searching for john on name field to returen johnson, johns etc.

I'm trying to override the IQueryable GetQueryable(IQueryable source) method on the QueryableFilterUserControl class. To filter my results. Does anyone know the best way of achieving this?

If this were and IQueryable<T> it would be easy as I could return the results of a .Where() clause.

There is an ApplyEqualityFilter(IQueryable source, string Column.Name, object value) method on the QueryableFilterUserControl class but this performs a direct comparison.

View 1 Replies

ADO.NET :: Convert From Linq.IQueryable To DataTable?

Aug 23, 2010

Is there option to convert from Linq.IQueryable to DataTable with some sort of CopyToDataTable() function. I am trying this.

View 2 Replies

C# - Iqueryable Intersect Fails When Applied Twice?

Feb 11, 2011

I have a series of parameters stored in rows in the database, and I'd like to return rows that satisfy both input parameters. The parameters come through in the URL, like "&msg_type=20560&status=101"

I have code that works fine, but only if there's one parameter. If there are two, it empties out the results. Here's my code:

[code]....

View 1 Replies

IQueryable Linq To SQL With Multiple Operators

Jul 4, 2010

I'm creating a repository and service layer in my app, and my repo has a very simple function

Public Function GetRegions() As IQueryable(Of Region) Implements IRegionRepository.GetRegions
Dim region = (From r In dc.Regions
Select r)
Return region.AsQueryable
End Function

Now in my Service layer I've got a function like this

Public Function GetRegionById(ByVal id As Integer) As Region Implements IRegionService.GetRegionById
Return _RegionRepository.GetRegions().Where(Function(r) r.ID = id).FirstOrDefault
End Function

But i can't figure out how to add And r.isActive = True

how to have multiple operators in this query?

View 3 Replies

ADO.NET :: Calling An IQueryable With Multiple Parameters?

Dec 23, 2010

the problem i am having is passing in multple parameters are part of my Function(p) call... i'll explain further..

This is my interface: it might have errors further though through this is still in development..

IRepository:

[Code]....

This is my repository, inheriting the interface above

[Code]....

And finally in my code-behind i am calling the SingleEntity - this is where i must be going wrong....?

If i call it with a single parameter then it's fine.. multiple and it goes awry..

I have put comments in the section i can't seem to figure...

[Code]....

When i run the code i get the following error:

[Code]....

View 7 Replies

MVC :: Using An Interface To Create A List / Iqueryable?

Mar 3, 2011

I currently have a number of lists in my solution, here is an example

[Code]....

and then in the repository

[Code]....

how would i do the same thing with an interface and an Iqueryable rather than a class and a list?

View 1 Replies

DataSource Controls :: Iqueryable Get Most Recently Updated?

Feb 2, 2010

I have a Iqueryable problem

<%= Article.Replies.OrderBy(r => r.Created).First().Member.Username %>

I want to get the most recent Replies that is part of the Article

"Article.Replies" gets all the replies

So now I want to Order by Replies.Created by descending And then just take the first one from which i can get the members username fine. Im having a syntax problem with doing the orderby descending and by picking the first.

View 2 Replies

State Management :: How To Store IQueryable Value In ViewState

Jan 3, 2011

i want to store IQueryable value to ViewState. my code is as below:

Private
Property _Query()
As IQueryable
Get
Return
CType(ViewState("_Query"), IQueryable)
End
Get
Set(ByVal value
As IQueryable)
ViewState("_Query") = value
End
Set

but when i run my page i get following error:

Type 'System.Data.Linq.DataQuery`1[[DynamicQueries.VW_EmployeeProfile_Filter, DynamicQueries, ersion=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable

what should i do to get rid of this error. previously i was doing like this:

Private Shared _Query As IQueryable

but problem is that in Multi users environament, Shared variable is making problem, that is why i want to store it in ViewState.

View 4 Replies

MVC :: IQueryable Casting To IOrderedQueryable Doesn't Work?

Nov 10, 2010

I am passed an IQueryable that might be already be ordered and that therefore might be an OrderedQueryable. I need to apply it a new ordering via reflection, anb before choosing if calling either OrderBy or ThenBy I need to now if the Queryable is IOrderedQueryable.

Now comes the problem! To see if may variable say query is an IOrderedQueryable I do:

IOrderedQueryable orderedQuery = query as IOrderedQueryable;

One might expect orderedQuery be null in case query is not an IOrderedQueryable ! INSTEAD orderedQuery is NEVER NULL. It takes the value of a different type!

I understand that this might happen because of deferred execution...

I tried also: query is IOrderedQueryable and it is always true!

How can I verify if query is actually an IOrderedQueryable before getting an exception when calling ThenBy?

The IQueryable comes from the Entity Framework 4.0

I am able to see it if I access the object that is behind the interface, but this way I would loose the benefif of using interface, and my class might not work with a different implementation of the IQueryable.

View 2 Replies

DataSource Controls :: How To Select Multiple Columns Into IQueryable

May 18, 2010

How do I select multiple columns into IQueryable<Employee>?

View 2 Replies

DataSource Controls :: How To Get Data From System.linq.iqueryable

May 26, 2010

I am using System.Linq.Dynamic to create the following query at runtime:

[Code]....

I can then successfully display vMediaQ in a GridView.But I need to be able to access the individual fields (column headers and data) in vMediaQ, which is of type System.Linq.IQueryable.

View 11 Replies

Forms Data Controls :: GridView Datasource Is A IQueryable Is Not Displayed?

Aug 4, 2010

I have a query that joins two tables (in Linq) so I usethe result as an Iqueryable. I want the Query result to be displayed in a gridview, but for some reason I see nothing on the gridview.(I also tried without the join and just using the IQueryable result -and still nothing)

[Code]....

why is doesn't work, or link me to an examlple that is similar - (Also is there another way to use the result of a "join" not as IQueryable)

View 2 Replies

ADO.NET :: Error - Can't Implicitly Convert Type 'System.Linq.Iqueryable

Aug 25, 2010

If I have below code, how to make it work as it has below compile error:

Error: cannot implicitly convert type 'System.Linq.Iqueryable<system.data.DataSet> to 'System.Data.Dateset'. An explicit conversion exists.

public DataSet GetProductList()
{
using (var sdatabase = new DatabaseDataContext())
{
IQueryable<DataSet> result = wmsdatabase.ExecuteQuery<DataSet>(@"SELECT productid, productname from product group by productid, productname").AsQueryable();
return result; // Compile error here
}
}

View 1 Replies

ADO.NET :: Dynamically Adding MyColumn LIKE '%@MyParameter%' To The Linq IQueryable Object

Jan 11, 2011

My situation is as follows:

I do some filtering on the IQueryable<MyType> object using the Contains() function in Linq, which in effect adds: MyColumn LIKE '%@MyParameter%' to the linq requestI want to make the function more generic, which could operate on a IQueryable object of an unknown type. In such case I do not know the type yet, therefore I can not add a standard .Contains() function. All I have present are the IQueryable object, the MyColumn and MyParameter as a string text. I need to be able to add "MyColumn LIKE '%@MyParameter%'" to the Linq object, dynamically ...

How can I write a piece of code that would run the Contains() on the IQueryable, knowing the Column name (as string) and the parameter value (as a string too) - I basically want to add this: MyColumn LIKE '%@MyParameter%' to the Linq where clause.

I have found something doing the .Where() function dynamically, but I do not entirely understand what is happening in there, so I struggle to convert it to Contains():

[Code]....

adding dynamic .Contains() to the IQueryable object only using the string column name and the string value

View 3 Replies

MVC :: Error In View While Looping Trough IQueryable(of T) Entity From A SQL View?

Jan 18, 2011

when I'm building a menu in a view I get following error when code reaches <% Next item%> :

System.InvalidOperationException was unhandled by user code

Message=The value of a property that is part of an object's key does not match the corresponding property value stored in the ObjectContext. This can occur if properties that are part of the key return inconsistent or incorrect values or if DetectChanges
is not called after changes are made to a property that is part of the key.

Source=System.Data.Entity

My view: (its a userview)

[Code]....

My Model
[Code]....

My Datasource
[Code]....

I use this way of looping frequent the only thing is that this is that this entity has a view as source and not a table, so I think it has to be related with that.

View 3 Replies

ADO.NET :: Saving IQueryable In Cache Error "The ObjectContext Instance Has Been Disposed And Can No Longer Be Used For Operations That Require A Connection"

Oct 29, 2010

i want to save a IQueryable in cache like this:

[Code]....

However when i try to retreive it and use it i get this error: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

View 5 Replies

ADO.NET :: Creating Dynamic Expressions For Lambda IQueryable Expressions?

Sep 30, 2010

I have a ListBox that contains userNames which is inputted by a user during run time. This number of items in the ListBox is dependent on the user's input. These userNames will then be used in a Lambda expression like this:

var vHandleResult = vHandleResult.Where(a => a.UserName.Contains("userName"));

This works fine when there is only 1 user in the ListBox but doesn't produce the correct results when there are multiple items in the listBox. I tried manually creating the expression which should be written as this:

var vHandleResult = vHandleResult.Where(a => a.UserName.Contains("userName1") || a.UserName.Contains("userName2") || a.UserName.Contains("userName3") || a.UserName.Contains("userName4"));

I tried forming the "a.UserName.Contains("userName") expression as a string which is dependent on the number of the items (using foreach) and then just plug in the resulting string in the expression but it seems that it doesnt accept string as an expression.

View 2 Replies

Add Code To Know Visitors Count And Online Visitors Count?

Jan 5, 2011

How to add code to know visitors count and online visitors count ?

is there a good control or code ?

I use ASP.Net, C#.Net ad SQL Server

View 5 Replies

Parameter Count Does Not Match Parameter Value Count?

Apr 21, 2010

We're getting a server error saying "Parameter count does not match Parameter Value count." Anyone have any idea what this could mean?

[URL]

Our site's on ASP.NET Webforms running DotNetNuke as a CMS.

I've tried uploading an older version of the web.config file but it doesn't seem to have changed since the error came up. It wasn't in any of our recent module file uploads because I reuploaded the old files from this morning that we changed.

Could any changes in the database cause this or would it have to originate from an error in the code?

View 2 Replies

How To Use Count Command In Sql

Sep 14, 2010

how to use the count command?and how can store the result of count command in a veriable of integer type?

View 4 Replies

ADO.NET :: How To Use Count In LINQ

Dec 1, 2010

Im new for LINQ, how can i count the records in this code

[code]....

So i can say Count records and its = PValue so i can use that in a EVAL(PValue) and get the total value of the records.

View 1 Replies







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