linq

Converting a "DBML" file to a "SQL database file"

I have the DBML file of a database and would like to generate an SQL database file from this file. Thanks ...

TemplateField Not Updating In GridView using LINQDataSource

Im using a LINQDataSource to populate a GridView of Universities. Each University has an associated State, which is in another table and associated by a foreign key (StateID). I have a TemplateField in the GridView so that when you view it normally it displays the StateName which comes from the State table and when you edit it shows a ...

LINQ - IEnumerable vs List - What to Use? How do they work?

Hello everybody ::- ). I have some doubts over how Enumerators work, and LINQ. Consider these two simple selects: List<Animal> sel = (from animal in Animals join race in Species on animal.SpeciesKey equals race.SpeciesKey select animal).Distinct().ToList(); or IEnumerable<A...

How to sort data in GridView in asp.net

How to sort datatable obtained by GridView according to some column. I am trying to do something like this but it is not working. protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { if (sender.GetType() != typeof(GridView)) return; DataTable dt = (DataTable)((GridView)sender).DataSource; DataTa...

SQL generated by LINQ for logging

Hi all. Plz help. I have this query and its result implements IEnumerable. RoutesEntities routesModel = new RoutesEntities(); LocalesEntities localesModel = new LocalesEntities(); var routesQuery = from rs in routesModel.Routes.ToList() join ls in localesModel.Locales.ToList() on rs.LocaleID equal...

Is this LINQ Query too long?

I'm new to LINQ, and don't want to over do it and make this code hard to maintain. What do you think, is this LINQ Query too long? IList<ListViewItem> data = runAnalysis.PassAnalyses.Cast<PassAnalysis>(). Select(passAnalysis => passAnalysis.GetValue(PeakStatistics.PeakStatisticsProperty)). SelectMany(peakStatistics => peakStatistic...

LINQ To Entities then SQLCompact

Hello everybody ::- ). I hope somebody wants some easy reputation by answering a simple question ::- ). How are you? Ok... joking ::- D. The question is about how LINQ to Entities works with SQL Compact. First of all, is there any way to profile stuff sent to an SQL Compact database? Apparently the Microsoft SQL Server Profiler does n...

LINQ to SQL group by with take

I have a table that looks like this: Id GroupId Value and it has about 100 rows How can I return the top 10 rows for value but with no duplicating GroupId? ...

Why is this LINQ Where clause not returning results?

We have an entity with DateTime property DateDestroyed. A query needs to return results where this value is between nullable DateTimes startDate and endDate. The where clauses I have are: .Where(x => startDate.HasValue ? startDate <= x.DateDestroyed : true) .Where(x => endDate.HasValue ? x.DateDestroyed <= endDate : true); The query ...

LINQ to SQL caching problem

Hi, this should be pretty simple. I have LINQ to SQL (C# 3.5 / SQL Server) working well, with a simple relationship in place between two tables Conferences and ConferenceAttendees. I have already created and committed a Conference, then I add 3 ConferenceAttendees using the following code (repeated 3 times): ConferenceAttendee NewAtte...

Merging dictionaries in key level and then in value level

I have two dictionaries like Dictionary<String, String> one = new Dictionary<string, string> { { "A", "1" }, { "B", "2" }, { "C", "3" }, { "D", "4" }, { "E", "5" }, { "F", "6" }, { "G", "7" }, { "H", "8" } }; Dictionary<String, String> two = new Dictionary<string, string> { { "A", "1" }, { "B", "...

Linq to NHibernate projection to anon. type results in mystifying cast error

I have an TaxWork entity which is persisted using NHibernate. This entity has the following properties (among others): public virtual TaxWorkType Type { get; set; } //Kctc.TaxWorkType is an enumeration public virtual TaxWorkStatus Status { get; set; } //Kctc.TaxWorkStatus is an enumeration public virtual LegalWorkPriority Priority { get...

Calculating Total Count of Items in List<T> for multiple KeyValuePairs in Dictionary<string,List<string>>

I have a Dictionary<int,List<string>>. I have multiple KeyValuePairs so int the first KeyValuePair the List may have 10 items in it, the second KeyValuePair may have 100 etc. I need to work out the total count for all items in each list so in my example above I would have a result of 110. ...

linq query dynamically add where condition ?

I want to filter records dynamically on user choice. The user may choose to show the debit amount greater than credit or credit amount greater than debit. Accordingly I want to put a condition similar to either totDebit>totCredit orTotCredit>totDebit` Dim query = _ From product In Bills.AsEnumerable() _ Group product By ...

Custom Method in LINQ to SQL query

Is it possible to use custom method In query for example: var result = from u in context.MyTable where MyMethod(u) == 10 select u; ...

How do I update a foreign key efficiently in LINQ to SQL/SQLMetal?

I ran into an issue trying to update a foreign key field: record.ForeignId = newId; It bombs with "Operation is not valid due to the current state of the object" due to SQLMetal code that throws System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(). I was not the first to hit this issue: http://stackoverflow.com/questions/2...

Linq Where value is in Array

IEnumerable<string> periods = new string[] {"ABC", "JKD", "223A"}; var someData = from p in returns from d in p.ReturnDet where p.Year > 2009 where d.Period <is in periods array> How do I select values where the d.periods are contained in the periods array? ...

Linq extracting objects

Hi all - I have a JSON "multi-level" response that I need to deserialize and from the deserialized classes structure I need to extract all the objects of a certain class. Below the code I'm using, at the end I find that my result is empty, not populated. // given these two classes: [DataContract] public class ThingsList { [DataMemb...

Parsing Text Data File With Linq

I have a large text file of records, each delimited by a newline. Each record is prefixed by a two digit number which specifies it's type. Here's an example: .... 30AA ALUMINIUM ALLOY LMELMEUSD2.00 0.35 5101020100818 40AADFALUMINIUM ALLOY USD USD 100 1 0.20000 1.00 0 100 140003 50201008180.999993 0.00 0.0...

LINQ Query to match a sequence

Hi, I have a result set, say clientList. And I want to make sure that ALL the clients in the ClientList have a Profession as "Banker". Let the result of the query be a boolean value. How can I write the LINQ or lambda expression query to get the result? ...