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


Similar Messages:

C# - Linq To SQL Mplementation Of Query Operators Except The Contains() Operator?

Mar 26, 2010

I have a local collection of record Id's (integers).I need to retrieve records that have every one of their child records' ids in that local collection.
Here is my query:

public List<int> OwnerIds { get; private set; }
...
filteredPatches = from p in filteredPatches
where OwnerIds.All(o => p.PatchesOwners.Select(x => x.OwnerId).Contains(o))
select p;

[code]...

I am getting this error:Local sequence cannot be used in Linq to SQL mplementation of query operators except the Contains() operator.I understand that.All() isn't supported by Linq to SQL, but is there a way to do what I am trying to do?

View 5 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

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

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

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

DataSource Controls :: How To Select Multiple Columns Into IQueryable

May 18, 2010

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

View 2 Replies

Web Forms :: Dynamic Comparison Operators?

Feb 15, 2010

What is the preferred way to handle this? Delegates? I have a dropdown box of comparison operators = <, <=, > , >=, == which is used to set up a filter. The filter expression is exactly the same for every case other than the operator. I can do it through a switch, but I am sure there is a one liner that can handle to entire problem. Just not sure what it is?

case <
If a < b
case > [code]....

View 4 Replies

C# - LINQ To Entity Framwework Multiple Joins With Multiple Dynamic Search Criteria?

Jul 2, 2010

The gist of the problem is that we have an alumni table (one record per person) and also a couple of other tables (one to many) that have degree info and interest info. In a search screen in our app you can search for criteria that spans all three tables (there are actually more fields and tables than shown in the example below but I am trying to keep it simple).

The code below works (properly returns people without degrees for example) but still feels a little clunky or over-engineered to me. Are there easier ways to do this? NOTE: I have been through quite a few iterations/approaches to making the correct data be returned.

[code]....

View 1 Replies

ADO.NET :: LINQ To SQL - Multiple Joins With Multiple Conditions?

Jan 28, 2011

I have some problems trying to query my database. The problem is that I'm not sure how to multiple join tables in my database.

tables to make it easier:

[code]....

What I'm supposed to do is to find all the teachers (predavac) who were teachers on the specific activity (aktivnost) and who had specific attendee (polaznik). The problem is I'm not sure how to do multiple joins on this one.

View 1 Replies

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

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

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

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

ADO.NET :: Linq Multiple Where From Second Table

Dec 16, 2010

Tables:

WORKORDER and CUSTFIELD

Fields:

WORKORDER = WORKORDERID

CUSTFIELD = WORKORDERID, CUSTFIELDNAME, CUSTFIELDVALUE

There are multiple different type of name/value pairs. I want to specifically return the custfield value where custfield name is "INCIDENT", and the custfield value where custfield name is "NETWORK" all for the appropriate WORKORDERID

I've tried a few different ways and just can't grasp how the linq is supposed to go to get the results I want. I can get an incident value, or network value, but not both.

I have the proper association set up in the dbml so both of these work to get the single value:

var b = from i in edcwdv.WOCUSTFIELDs join p in edcwdv.WORKORDERs on i.WORKORDERID equalsp.WORKORDERID where i.CUSTFIELDNAME.Contains("INCIDENT") select new { i.CUSTFIELDNAME, i.CUSTFIELDVALUE, p.WORKORDERID };
var incident = from wo in edcwdv.WORKORDERs orderby wo.WORKORDERID where wo.WOCUSTFIELDs.CUSTFIELDNAME.Contains("INCIDENT") select new { wo.WORKORDERID, wo.WOCUSTFIELDs.CUSTFIELDVALUE}; So essentially i want to pull the value for each of the fields, INCIDENT and NETWORK

View 2 Replies

C# - Send Multiple Emails (via LINQ To SQL)?

Jun 13, 2010

The objective is to send automated emails to which of whom come from the results of my LINQ to SQL script. As I am not sure on 'automated' stuff I was going to approach this in the aspect of having a field in the table that the results are taken from change after the emails have been sent i.e. obj.EmailSent = true; - So that everytime the admin homepage is loaded it isnt sending it out again (eliminating duplication).

From that I would have to create a method to detect a new year and upon that reset all entries of the EmailSent field in the DB table to 'false', but for now its just the initial problem thats causing confusion.

I was going to opt for a 'foreach' solution so that all the recipients, individually, get their emails and not all together. Its the 'foreach' I'm not sure on as well as setting all the results collected to the new value of 'EmailSent' to 'true'.

Here is my attempt:

C#:

[code]....

View 9 Replies

ADO.NET :: Linq On Multiple Tables With Same Columns

Aug 17, 2010

I have a partitioned db where several tables have the exact same structure. I'm able to query the tables using linq, but only by quering the individual tables 1 at a time and by using the explicit table name. For example at the moment, I have 8 tables so I have something similar to the following:

[Code]....

Is there any way, that based on a certain value (stringValue), I could determine which table to query and then code the linq query just once?

View 2 Replies

ADO.NET :: Searching Through Multiple Tables (Linq To SQL)?

Aug 12, 2010

I have a couple tables that are kind of unrelated - id like to search through both of them and create a type that i can sift through later

something like this doesnt work

[Code]....

I basically want to create a list of "AnimalSearchResults" that contains all dogs and all cats that have that name Whats the best way to do something like this?

View 6 Replies

C# - Linq To Sql Making Multiple Calls In .net Mvc 3

Mar 18, 2011

When I am updating a record with linq to sql my DeleteLesson() method is getting called multiple times.My controller looks like this :

public ActionResult Delete(int id)
{

deleteLesson(id);[code]....

EDIT.also if I use confirm = "Do you want to delete" in ajax options I will have to click okay three times.

View 1 Replies

C# - Linq - Group By Multiple Tables?

Aug 8, 2010

Using Linq to Sql how do i group the following 2 tables.

Orders Table:

CustomerID | Name |Date
1 | order1 | 2010-01-01
2 | order2 | 2010-01-01
2 | order3 | 2010-04-01

Calls Table:

CustomerID | Name |Date
1 | call1 | 2010-01-01
3 | call2 | 2010-06-01
2 | call3 | 2010-05-01

I want to group the two tables by date , Result:

Date | Orders | Calls
2010-01-01 | 2 | 1
2010-04-01 | 1 | 0
2010-05-01 | 0 | 1
2010-06-01 | 0 | 1

i know how to group a single table ,from o in Orders group o by o.Date.Date into og select new {Date = og.Key,Orders= og.Count()};

View 2 Replies

ADO.NET :: How To Declare Multiple Groups In LINQ

Aug 17, 2010

How can I declare multiple groups in LINQ? I get this error "Range variable 'Group' is already declared." Error found in bold and underlined text below.

Dim SportsWear = From c in dbContext.SportsTable Group Join grp_Attire In dbContext.AttireTable On grp_Attire.AttireId Equals c.AttireId Into Group From sportsAttire In Group.DefaultIfEmpty() Group Join grp_SportType In dbContext.SportType On grp_SportType.TypeId Equals c.TypeId Into Group From sportsType In Group.DefaultIfEmpty() Select New With { _ .Attire = sportsAttire.AttireName,.Type = sportsType.TypeName}

View 1 Replies







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