ADO.NET :: Make A Linq Query Dynamic In The Pseduo Code

Sep 9, 2010

is it possible to make a Linq query dynamic in the following pseduo code (to show what I'm trying to do)

[Code]....

where a2 and a3 and a4 are being populated from user controls and only one will apply. So query is done by state, zip or by city, but not by more than one, so the other two would be null. So the operator is really "OR" but I haven't found anything on a "or" or "whereOr" operator.

View 9 Replies


Similar Messages:

Simplify LINQ-To-Entity Query, And Make It Dynamic

Dec 4, 2010

I have this query for getting data through Entity Framework, which works today. Thing is, i want to create the query dynamically, i.e build it up in blocks, but i can't figure out how exactly to do it. I believe if i can somehow save one of the values that i retrieve in the beginning i can do it, but now i retrieve it twice (probably a bit slow as well? Unless the compiler fixes it before quering). Makes sense? Here is the LINQ:

[code]....

I.e based on if various variables have values.

View 1 Replies

ADO.NET :: Dynamic LINQ Query / Use "if Statement" In Linq Query

Feb 11, 2011

I want to use "if statement" in Linq query. How can I do this situation?

For example:

if txtAge.Text=="", I will not use that in Linq Query.

else txtAge.Text!="", I will use that in Linq Query.

View 8 Replies

ADO.NET :: Query Dynamic Table In LINQ?

Jan 17, 2011

I have a table created on the fly. The table structure is dynamic.

This is the table structure generated by the end of year 2010

DealerCode, 201010, 201011, 201012

This is the table structure generated by the end of Jan 2011

DealerCode, 201011, 201012, 201101

What I need to do is selecting all data and then bind it into a gridview

To build a LINQ query, we need to drag the table into dbml file first. As we don't know how the table look like, can we add it in dynamically? Are there any other solutions?

View 1 Replies

ADO.NET :: Dynamic Table Name Linq-to-sql Query?

Sep 20, 2010

I am writing a function in which i generate autocode in specific format i want to make this function generalize so that i send tablename and columnname parameter and function return the next code. I am using linq to sql with MVC e.g. i want to make table name and column name dyanamic

[Code]....

View 3 Replies

ADO.NET :: How To Make Var Query Static For Linq

Oct 6, 2010

I was use SQL Connection to Access Data Base in Past and When Select Data in DataSet make it static & than it can avaliable on class level.I click on Edit Button its avalibale because its Static.Than now i think try it with LINQ it's provide easy Access to Data Base; in Insert/Update/Delete than SQL Connection it look's me great when i use it.

But i don't know how to make var Query Static for its class level avaliability. i can define it by my code

public static DataSet DsCustomers;
protected void Page_Load(object sender, EventArgs e)[code]....

in LINQ example i want to make sure that SelectQuery is avaliable on Class level & want to make it static

View 3 Replies

Generate Dynamic LINQ Query In SharePoint

Nov 25, 2010

I have a page with filters and accordingly to what the user selects, it has to generate a query. I'm using this code:

[code]....

However Linq-To-Sharepoint doesn't convert most of this to CAML and the list I'm querying has more than 50000 items. It takes about 4-8 seconds to retrieve the items which is not acceptable.

I've been trying to generate a dynamic query but so far I haven't been able to get it to work.

With AND and OR operations to generate the query I could put all those conditions on code and increase performance.

View 1 Replies

ADO.NET :: Linq Search - Dynamic Query Based On User Input?

Jan 12, 2011

I have two text boxes for the user to enter UserName & First Name, both these fields are optional and not mandatory to fill.

once the user presses the Search button, i execute the following query to fetch matching records.

[Code]....

The problem is, in cases where User leaves both the textbox or one of the textbox empty/blank, in that case that particular field should be removed from where clause.

More like if something is entered then search for that particular record otherwise search for all the records.

View 2 Replies

DataSource Controls :: Compile In Order To Get The System.Linq.Dynamic Namespace / Dynamic Linq Error

Apr 20, 2010

I've added the Dynamic.cs file to my project and have set it's Build Action = Compile in order to get the System.Linq.Dynamic namespace.

However, when I try to use any of the new code I am getting an ambiguous call error; see below.

[Code]....

View 2 Replies

C# - Optimized This Code And Make It More Dynamic?

Sep 21, 2010

is there a way i can optimized this code and make this extensions on web.config settings so i can read from there and in future if i need to add or remove i should be able to do easily?

if (fileExt.ToLower() == ".rtf" ||
fileExt.ToLower() == ".xls" ||
fileExt.ToLower() == ".doc" ||
fileExt.ToLower() == ".png" ||

View 5 Replies

Rewriting This Linq Query To Move It From Code-behind To DAL As Reusable Object?

Apr 4, 2011

I'm working to move my simple asp.net website to a three layer architecture. Currently I have Linq queries like the one below in my code-behind files. Basically this code snippet retrieves a collection of customer data from the database and then binds it to a grid control.

I'm wondering if someone can guide me on how to rewrite this in order to move it to my newly-created data access layer. I'm thinking I will turn it into a class (e.g. GetUserBoxesByStatus()) that can be reused throughout the site.

var boxes = from p in sbm.Packages
where p.UserID == CurrentUserId && p.StatusID > 1 && p.StatusID < 3
select new { p.PackageTag, p.PackageName, p.DateReceived, p.DateShipped }; [code]....

Some of the options that I've investigated but have not had success implementing are the following:

DataTable --- returning a DataTable seems like the best solution but it also appears to require a lot of potentially unecessarry code to define a table (isn't the data source already mapped in my Linq 2 Entities dbml?)

IEneuerable --- I think I could pass an IEnumerable list between the layers but after reading many tutorials about Linq I'm still a little lost DTO --- Conceptually I think I understand what a DTO is but I am not clear on how to begin implementing this approach POCO --- Again, the concept seems logical enough but I don't know how to put this into practice

how they would tackle this using one of the above or some other solution.

View 1 Replies

Forms Data Controls :: Sql To Linq Query / Looking To Translate An SQL Query Into Linq?

May 28, 2010

I'm looking to translate an SQL query into linq

INNER JOIN Usrs ON
SAQ.UserId =
Usrs.UserId AND Scan.UserId =
Users.UserId

I'm not sure how to include the "AND" in the LINQ statement.

View 3 Replies

DataSource Controls :: SqlDataSource And Parameters Query / Trying To Accomplish Is Building Dynamic Query

Aug 22, 2010

1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like

SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.

Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).

2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query

(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).

If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.

View 11 Replies

ADO.NET :: Build A Linq Query / Linq Random Selection?

Sep 14, 2010

I've build a linq query.But i want a random selection so its not always ID : 1,2,3,4,5,6 How can i randomize this var? I like to bind it to a repeater.//TagCloud:

Random rand = new Random();
var tc1 = from i in JumpTide.cms.menu.GetMenuItems(32)
select new

[code]...

View 1 Replies

DataSource Controls :: How To Convert Sql Query Into Linq Query

Mar 10, 2010

select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid

View 5 Replies

Dynamic Where Condition In Linq To Sql Or Linq To Entity?

Dec 24, 2010

We would like to perform something like this

string strCondition = "FirstName=='abc'"
from p in People.Where(strCondition) select p

In our architecture we are usign both Linq-Sql as well Linq-Entity. So please give some thoughts wehter it is possible or not and is there any way to perform this?

View 2 Replies

Linq Query Returning Less Records Than Sql Query?

Mar 19, 2011

I am facing a big problem with simple linq query.. I am using EF 4.0..

I am trying to take all the records from a table using a linq query:

var result = context.tablename.select(x=>x);

This results in less rows than the normal sql query which is select * from tablename;

This table has more than 5 tables as child objects (foreign key relations: one to one and one to many etc)..

This result variable after executing that linq statement returns records with all child object values without doing a include statement.. I don't know is it a default behavior of EF 4.0 . I tried this statement in linqpad also..but there is no use... But interesting thing is if I do a join on the same table with another one table is working same is sql inner join and count is same..but I don't know why is it acting differently with that table only.. Is it doing inner joins with all child tables before returning the all records of that parent table?

View 2 Replies

Linq Query - How To Select Inner Query Into List

Oct 17, 2010

I am writing a linq query to select a blogpost,

[code]....

The blogpost i am testing got 3 tags attached to it. The table structure is:

(table)BlogPost -> (table)BlogPostTags <- (table)Tags

So the BlogPostTags table only contains 2 fields, BlogPostID and TagID.

When i run the query above i get 3 results back. Same blogpost 3 times but with 1 tag in each. It should return 1 post with 3 tags. The problem lies in the Tags query above.

View 1 Replies

ADO.NET :: LINQ Entity Framework Query - Construct "nested" Query?

Jan 22, 2011

I have a web app for our golf club. When I compute handicap index for each golfer, I have to select the most recent scores and then a subset of those scores depending on how many rounds of golf the golfer has played. All the scores are entered into a single SQL Express table called "Rounds". Verbally, this is what I'm trying to do:

1) select the twenty most recent golf scores (sort on date descending, "take(20)") [if less than 20 records, then select all available];

2) for this set of records, select the 10 lowest scores (or smaller number if golfer has less than 20 rounds);

3) compute the average round differential for the subset of records, etc. to calculate handicap index (this step is working ok...)

My current VB code has this LINQ query (which is flawed -- it selects the lowest handicap differential scores of ALL records for the filtered user):

[Code]....

How do I modify this query to accomplish items 1) & 2) above? It seems this should be simple, but my experience with queries is still limited.

View 2 Replies

Using Variable From Code-behind In SQL Query, C# / Add WHERE UserID = User2 To The SQL Query?

Apr 26, 2010

I am trying to use a variable from the code-behind page in a sqlDataSource WHERE statement. I am using Membership.GetUser().ProviderUserKey to obtain the UserId of the logged in user and I would like to only show record that have this UserId as a foreign key. How can I write the SQL for this?

Here is what I have so far:

SQL Query:

SelectCommand="SELECT [UserID], [CarID], [Make], [Model], [Year] FROM [Vehicle]"

Code-Behind

String user2 = ((Guid)Membership.GetUser().ProviderUserKey).ToString();

And I want to add WHERE UserID = user2 to the SQL Query.

View 2 Replies

Display Dynamic QR Code In Crystal Report In .net Page C# Code-behind

Mar 14, 2011

I'm using CRv9 and want to make use of Google Charts API for generating QR code on fly (in asp .net) and display it in the Crystal Report in a PDF format.I have spent the whole day looking for solution with no luck. The way we output the report is we use .rpt file, feed it with data and use Response.OutputStream to feed to browser. No CrystalReportViewer control hence CSS solution is not an option.

Now, I got as far as added an OLE Object from file with Link, which I would be overwriting every time the new QR code is generated. I apreciate that CR requires it to be a bitmap, so I was planning to download and convert the google's generated PNG file to BMP, that's not an issue. The problem is that Image in the report does not update after I replace the file. Meaning, it displays the original image, which was added as an OLE Object.

If I open this report in CR designer, the image gets refresh/updated and I'd have to save changes to the report to see this new image next time I generate a PDF file.The question is really how to achieve a dynamic image in Crystal Reports 9? Remember, Picture object did not have a Graphic Location property until vXI, so I cannot use that.

Manipulations with DataSets is not an option either as we're not giving report a datasource, instead we just map the fields with FormulaFieldDefinitions.

sample qr code url: https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello%20world&choe=UTF-8

View 3 Replies

ADO.NET :: IN Query, Linq To Sql?

Aug 2, 2010

I have a list which contains few email ids

List<string> EmailId= { ....}
Now I have a db table Users. I need to select all users whose email exist in the above list. In sql we could write "where emailid in ('email1', email2' ,...)"

how to do this in linq to sqlquerable<Users> existingUsers = Users.getTable().where (u=>u.emailaddress in EmailId). I want to do some thing similar

View 2 Replies

ADO.NET :: Not Sure How To Do This Query In Linq To Sql

Sep 12, 2010

I need to figure out how to express this in linq to sql:I have one or more records that contain what is essentially a wildcard sql parameter, like '100_-___-2', which should match 100[any 1 char]-[any 1 char][any 1 char][any 1 char]-2, for example. Each login will have one or more of these 'datamasks' associated with it.I need to write a query in linq to sql that does something like:

select * from something
where fieldA = 'someValue' or fieldB = 'someValue'

so far, simple, but I also need to restrict the returned records to only those that match the user's 'datamasks'. I'm not sure exactly how to translate this to linq to sql... here is what a working query *without* the datamasks part looks like:

[Code]....

I need to tack on the datamasks part... can I do it right there in the same statement? or do I need to do a foreach loop on the datamasks records and append a new && condition for each one? hmmm... just thought of that as I was writing this.. I'll try that out. But I'm posting this anyway for more input... I guess that would look something like:

foreach (string mask in datamasks)
{
query = query.Where(item =>
System.Data.Linq.SqlClient.SqlMethods.Like(item.AccountNum, mask));
}

would that work? would each additional 'where' condition be 'appended' to the existing query definition?

View 3 Replies

Many To Many LINQ TO SQL Query

Mar 11, 2010

Users
Roles
UserRoles
MenuItems
RoleMenuItems

A User can have multiple Roles and a MenuItem can be accessed by multiple Roles. Now I want to write a method as follows:

public IList<MenuItems> GetMenuItems(UserRoles userRoles)
{
var menus = // LINQ query to get the MenuItems by UserRoles
return menus.ToList();

View 1 Replies

C# - LINQ To SQL Dynamic Select?

Jun 7, 2010

how to indicate which columns I would like returned at run-time from a LINQ To SQL statement?I am allowing the user to select items in a checkboxlist representing the columns they would like displayed in a gridview that is bound to the results of a L2S query.I am able to dynamically generate the WHERE clause but am unable to do the same with the SELECT piece. Here is a sample:

var query = from log in context.Logs select log;
query = query.Where(Log => Log.Timestamp > CustomReport.ReportDateStart);
query = query.Where(Log => Log.Timestamp < CustomReport.ReportDateEnd);

[code]...

View 2 Replies







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