C# - Clause Is Used Inside Linq Statement Produces Different Results Than When Used Outside?
Aug 8, 2010
I have the following statement:
List<string> tracks = new List<string> { "ABC", "DEF" };
var items = (from i in Agenda.AgendaSessions
select i).Where(p => p.Tracks.Any(s => tracks.Contains(s.Code)));
this returns all sessions which track contains either ABC or DEF, now when I rewrite the statement like the following, it returns All sessions regardless, as if the clause always yeilds into true,
var items = from i in Agenda.AgendaSessions
where i.Tracks.Any(s=> tracks.Contains(s.Code))
select i;
Update
if there are other clauses within the where, does that affect the results?
I am using Linq to SQL. Tables have timestamp columns and I am using regular Linq methodology in ASP.NET MVC.I do use detached entities and always try to do updates without first querying the database for the original entity. To update an entity I use context.Attach(entity, true) followed by context.SubmitChanges() and all is fine. The sql statement that gets executed looks like:
My application includes BUILDING table with columns BUILDING_ID, NAME, TOWN_ID, I run the LINQ query listed below and need to append two letters to buildings.NAME based on TOWN_ID. I assume that I need to place an "if" or "select" statement inside the query but I can not figure out how to do that,
I am having trouble with this I have 3 Data tables i use over and over again which are cached I would like to write a LINQ statement which would do the following is this possible?
T-SQL VERSION:
SELECT P.[CID],P.[AID] ,B.[AID], B.[Data], B.[Status], B.[Language] FROM MY_TABLE_1 P JOIN ( SELECT A.[AID], A.[Data], A.[Status], A.[Language] FROM MY_TABLE_2 A UNION ALL SELECT B.[AID], B.[Data], B.[Status], B.[Language] FROM MY_TABLE_3 B ) B on P.[AID] = B.[AID] WHERE B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1 AND B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1
Then i would like it to create a result set of the following
I have really stucked at a big problem using the AsyncFileUpload inside a TabContainer. It seems that when I have put the AsyncFileUploadControl inside a TabPanel in the TabContainer and now switch tab manually by clicking I receive an error that is another codefile than the .cs file. I cant understand what is causing this error ?
The Error that is highlighted in the code will be this:
In the code bdehind && syntax does not work, any ideas?
Entities ctx3 = new Entities(); var uniqueQuote = from quot in ctx3.Quotes.Include("aspnet_Users").Include("Enquiries") where quot.Enquiries.EnquiryId == selectedEnquiryId && [code]...
Error 2 Delegate 'System.Func' does not take '1' arguments C:LocalGarageFinderLocalGarageFinderEnquiryDetail.aspx.cs 56 33 LocalGarageFinder
Ive created a new LINQ To SQL class and dragged several tables across from my server, in my code I access them like this
[Code]....this is all ok, however, I have several stored procedures that I want to use as well, but when I drag the stored procedures across I get a compilatiopn error
Error 60 'DB_BL.DB_BLDataContext': type used in a using statement must be implicitly convertible to 'System.IDisposable'
how do I use stored procedures from LINQ with a using clause ?
I have a sql datasource with the ControlParameter called ddlDropDownList.
2 questions:
1. Is my syntax below ok, I am getting a runttime error that the syntax is incorrect.
2. I have the select statement set up the control parameter to get the selected value from the dropdownlist as shown below, is that syntax correct? especially the "selectedItem.value" for the propertyname property.
I just want to put together a SQL statement and load all my results into a table. I don't care about sorting or specifying which columns should be shown.
My SQL Statement changes what columns are returns, and I just want the results to show everything. I don't need bells or whistles at the moment - just all the results loaded into a table, every time.
I have a single column returning SQL data source and I want to use the data for a simple if statement, but for the live of me I can't figure out how to do it. *oh for the old days, I wrote the same thing in simple asp in about 45 seconds*
[code]....
For the life of me I can't figure out how to get that data into a variable or any way to access it. I know its probably simple. I have tried functions, etc off the net but everything I try results in another error.
My sql statement is not functioning correctly. The gridview does post the items correctly but the results are not correct. Can someone assist me with the sql statement where I'm going wrong with it?
I only have one being reffer to the code because I was testing to see it work. Eventually, the search will be base on multi select and the selected items are going to the stored procedure to search for the proper records.
The following is the site code and sql code. -carlos
Im using SQL Server 2005 and im using stored procedures. Is this possible? i need to get a number of results and do it in one SELECT statement or just one result set. Im using MS Chart Controls for reporting and they cant seem to process multiple result sets this is my problem, so basically to run a barchart i need to assign a column to the X axis and a column to the Y axis and it will then display my results.
My stored procedure below returns a result set with columns subpolicy_name, building_name, floor_name, room_name and total_savings. Im just wondering is it possible to split my total_savings column into 4 columns, for example subpolicy_savings, building_savings, floor_savings and room_savings, i need everything in a separate column. If you run this stored procedure you will see the result set.
I'm having trouble writing what should be a simple sub-query using LINQ to Entities. I have two tables: Customers and Orders that have a relation on the CustID field. Not all Customers have a record in the Orders table, while some have mutiple records. In traditional SQL, you could write the query like this: SELECT * FROM Orders where CustID IN (SELECT CustID FROM Customers) I know this could be done as a JOIN in both SQL and L2E, but my actual query is more complex (about 8-9 joins), so I am hoping to find a L2E sub-query equivalent. Something like this:
[Code]....
I know LINQ to Entities does not support the " IN " clause, so I am looking for something that will work in its place.
I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It uses Where conditions to narrow down the results, namely:
Gender. Current Occupancy < Max Occupancy Available Flag is Checked
I know this should return results but it keeps returning an empty set. Any ideas? Code is below
Dim selectedHalls = (From sh In dbHalls.Rooms _ Where sh.gender = Session("gender").ToString _ Where sh.max_occupancy > sh.current_occupancy _ Where sh.is_available = 1 _ Select sh.building_name).Distinct()
UPDATE: I've verified that the issue is with the statement where sh.is_available = 1, which doesn't make sense since this is a bit field.
I can't seem to change the order of the results coming back from a linq to sql query, I want just to return the distinct values from the field x.manufacturer in alphabetical order, this is what I have and it isn't working:
public IQueryable<string> Dropone() { return (from x in CAT.CatalogueDatas where x.Parent == null orderby x.Manufacturer select x.Manufacturer).Distinct(); }
Currently I get the distinct values in non-alphabetical order, in fact I'm not sure what order they're coming out in, don't think it's the order in which they appear though.
I have two tables, subscriptions and topics. Each subscription is related to a specific TopicID (PK for topics table). The first query works fine and retrieves the topicID's of all videos that were uploaded today. The problem occurs when I try and then use the results of query1 as a where-in clause for query 2. I keep receiving object reference not set to instance of an object.
Query 1 IQueryable<int> topics = (from t in dataLayer.Videos where SqlMethods.DateDiffDay(t.DateCreated, DateTime.Today) == 0 select t.TopicID).Distinct(); [code]....
I have looked at some samples around the net and they all seem to be identical to mine.