All Questions

Tagged with
Filter by
Sorted by
Tagged with
100 votes
1 answer
90k views

Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

I am working with .NET4.5 and VS2013, I have this query that gets dynamic result from db. dynamic topAgents = this._dataContext.Sql( "select t.create_user_id as \"User\", sum(t.netamount) as \"...
Matas Vaitkevicius's user avatar
19 votes
5 answers
344 views

Is there an elegant LINQ solution for SomeButNotAll()?

Here is what I'm trying to do overall. Just to be clear, this isn't homework or for a contest or anything. Hopefully, I've made the wording clear enough: Problem Given a set of strings in the same ...
chris's user avatar
  • 61.3k
17 votes
2 answers
16k views

When to use LINQ's .ToList() or .ToArray()

After running this code: var input = new List<T>( ... ); var result = input.Select( t => new U(t) ); U first1 = null; foreach ( U u1 in result ) if ( first1 == null ) first1 = ...
HappyNomad's user avatar
  • 4,508
11 votes
4 answers
3k views

Execution-Deferred IQueryable<T> from Dynamic Linq?

I am using Dynamic Linq to perform some queries (sorry but it's my only option). As a result, I am getting an IQueryable instead of an IQueryable<T>. In my case, I want an IQueryable<Thing>...
Jaxidian's user avatar
  • 13.2k
8 votes
2 answers
3k views

DbGeometry makevalid?

I'm new to this. I don't know how to use the SqlSpatialFunction MakeValid. I have a DbGeometry which is a polygon. This polygon is not valid and I want to make it valid. Can anyone explain how to use ...
Thomas Bolander's user avatar
5 votes
1 answer
3k views

Comparing two collections with IEquatable while using only LINQ

This question is for educational purposes only and I can solve it easily by using for loop that returns false on first mismatch. I am implementing IEquatable<CustomerFeedbackViewModel> on ...
Matas Vaitkevicius's user avatar
5 votes
3 answers
10k views

Combine two lists into one based on property

I would like to ask whether there's an elegant and efficient way to merge two lists of MyClass into one? MyClass looks like this: ID: int Name: string ExtID: int? and the lists are populated from ...
pzaj's user avatar
  • 1,072
3 votes
2 answers
2k views

Split a List of an Object group by some properties with lambda expression

This is My Type: public class MyObj { public long Number { get; set; } public string Name { get; set; } public string Message { get; set; } public DateTime RegisterDate { get; set; } }...
Saeid's user avatar
  • 13.4k
3 votes
2 answers
1k views

Linq's Enumerable.Count method checks for ICollection<> but not for IReadOnlyCollection<>

Background: Linq-To-Objects has the extension method Count() (the overload not taking a predicate). Of course sometimes when a method requires only an IEnumerable<out T> (to do Linq), we will ...
Jeppe Stig Nielsen's user avatar
3 votes
1 answer
1k views

Adding a character at the beginning of a string if it does not exist using LINQ

I have a string which I apply some LINQ methods. After applying a Replace, I would like to add a '/' character at the beginning of the resulting string if and only if it does not exists yet. For ...
Willy's user avatar
  • 10.2k
3 votes
2 answers
1k views

Create a parent -> children hierarchy from two collections

I have two separate collections instances filled with data List<Parent> parents; List<Child> children; two collections can be connected through Child.ParentId, and Parent.Children. ...
Goran's user avatar
  • 6,398
3 votes
0 answers
693 views

MVC view compilation using wrong .NET Framework

An existing web application is using .NET Framework 4.5.1. The project has the setting MvcBuildViews set to true. The project also uses a Prepend extension method for IEnumerable<T>. Stuff ...
AroglDarthu's user avatar
  • 1,091
2 votes
2 answers
5k views

convert foreach to linq expression

I have the following code which transforms a List of myCar objects to an Array of Car objects from a third-party web service so I can then pass the cars to the 3rd party web service: var cars = new ...
Ctrl_Alt_Defeat's user avatar
2 votes
2 answers
71 views

Linq Any() times out

I am trying to compare two data tables using Linq. Very simple tables, just one column but have about 44,000 rows. I use the following but when I trace it, when it gets to if (dr.Any()), it just sits ...
NoBullMan's user avatar
  • 2,108
2 votes
3 answers
364 views

Failure to implicitly convert class to base class when using LINQ IEnumerable.ToDictionary()

I have the following situation which is confusing me. Given: public class ThermoRawFile : MsDataFile { } public abstract class MSDataFile { } I am unable to run this LINQ IEnumerable.ToDictionary()...
Moop's user avatar
  • 3,501
2 votes
5 answers
3k views

Using C# LINQ to concat a filtered List<object> to List<string>

This is probably easy for someone more experienced with LINQ and the Lambda expressions in C#. I'm just starting out with them, so I must be missing something. I have a custom object like this: ...
crush's user avatar
  • 16.9k
2 votes
1 answer
542 views

Translating WITH ROLLUP SQL statement to LINQ

I need a help to translate a statement from LINQ to SQL SQL SELECT MONTH(ind_receita.lad_ins_date) as 'Month', SUM(ind_receita.valor) as Monthly_Value FROM ind_receita WHERE YEAR(ind_receita....
Lucas_Santos's user avatar
  • 4,668
2 votes
2 answers
227 views

How to sort IEnumerable with limited result count? (another implementation of .OrderBy.Take)

I have a binary file which contains more than 100 millions of objects and I read the file using BinaryReader and return (Yield) the object (File reader and IEnumerable implementation is here: ...
Amir Pournasserian's user avatar
1 vote
2 answers
2k views

Get the Substrings within the List<string> collection using Linq

I've a collection list. List<string> mycollections = new List<string>(new string[] { "MyImages/Temp/bus.jpg", "MyImages/Temp/car.jpg", ...
venkat's user avatar
  • 5,678
1 vote
1 answer
62 views

Compile a list of unique objects using LINQ

Having the pseudo code class Bar {int BarId;} class Foo { List<Bar> Bars; } Using Linq, how should I select all avaiable unique bars from the foo list ? List<Foo> foos = GetFoos(); //...
serge's user avatar
  • 14.6k
1 vote
1 answer
723 views

Inheritance and Polymorphism in LINQ Lambdas

I've got a couple of classes inheriting from a base class Public MustInherit Class BaseClass Public Property Name as String End Class Public MustInherit Class ClassA Inherits BaseClass ...
Basic's user avatar
  • 26.5k
1 vote
1 answer
1k views

Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Data.Entity.Infrastructure.DbQuery'

I receive this error when I put the following code: var rec = (bNoTracking ? tblOrders.AsNoTracking() : tblOrders); ... ... ... //error on next line: Cannot implicitly convert type 'System.Linq....
Sam's user avatar
  • 1,866
1 vote
3 answers
272 views

How to join two tables with null values in referenced fields

The table t1("PO1") and the t2("DTM") contains following values Table t1 PO101(string) Loop_Id (Int) Item_1 6 Item_2 8 --- Table t2 DTM02(string) Loop_Id(...
TonyP's user avatar
  • 5,751
1 vote
1 answer
568 views

Linq Return grouped Table as Datatable

I wrote a function that returns a DataTable Object. For the following code Public Function GetArtikelsAbove50(ByVal limit As Integer) As DataTable Dim query = _Set.Ten_Most_Expensive_Products....
ruedi's user avatar
  • 5,475
1 vote
0 answers
250 views

Ignore certain string in list of split string while splitting in c#

I need to split string in given lines based on list of string given. For this I use list of string to split line value and it works perfectly fine for most of the case but not for some of them. As ...
user2191393's user avatar
1 vote
1 answer
60 views

Linq to Entities filtering out default parameters

Say I have the below method where the insuredNumber is required to be populated but the remaining three parameters may contain default values as below Method Signature: public List<...
Phil Murray's user avatar
  • 6,456
1 vote
1 answer
1k views

How can I invoke several clients' async methods and aggregate the results into one task generically?

The following code is intended to reduce redundant code by allowing you to generically invoke the same selector on a set of "getters" (data retrieval clients) and have all of the results combined. The ...
Michael J. Gray's user avatar
1 vote
1 answer
422 views

Resultant LinQ Query to a new DataTable

Refer to earlier post/Question: LINQ to Swap few Columns to Rows of a DataTable using C# I want the resultant of the query interms of a new dataTable directly instead of defining columns in the new ...
venkat's user avatar
  • 5,678
0 votes
3 answers
136 views

Linq Select that will generate tied scores for similar values

I'm trying to generate a simple league table with positional numbers based on scores. e.g. Given the following List<Player> players = new List<Player>() { new Player { Name = "John", ...
Eoin Campbell's user avatar
0 votes
4 answers
330 views

handling no result found

Following line throw exception if there is no matching record found. Guid stuId= context.Students.FirstOrDefault(x => x.Name == student.Name).Id; I understand, i can handle above line var stuId=...
simbada's user avatar
  • 940
0 votes
4 answers
267 views

LINQ Replace Different String Values

I constructed a variable by parsing a text file with some addresses. FileInfo fi = new FileInfo(@"C:\temp\Addresses.txt") var ZipCodesAndCountryCodes = File.ReadLines(fi.FullName) .Select(...
FMFF's user avatar
  • 1,692
0 votes
3 answers
147 views

Using Anonymous method not preferred by .NET itself?

I am trying to learn the anonymous method and tried out this sample. So, whenever I am trying to call WriteLog function i can just use ()=> { return "someLogData" }; The advantage is that, I ...
now he who must not be named.'s user avatar
0 votes
2 answers
179 views

IEnumerable<> being skipped by foreach code; Converting IEnumerable<> to List<> doesnt return anything

Basically I have this code: public static async Task<bool> SubmitOrdertoBroker(CASOrderModel order, IEnumerable<CASOrderItemModel> modelOrderItems) { ObservableCollection<...
iceheaven31's user avatar
0 votes
5 answers
4k views

Using "contains" to query a list <Key-Value> in C#

In my code, I have "sourceElements" is a type of List<KeyValuePair<string, string>>. I need to query if the keys of this list contains a particular value and i tried this: ...
now he who must not be named.'s user avatar
0 votes
1 answer
1k views

Unable to use ICollection.ToList()

I am trying to call ToList() here: using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; namespace CSVStuff { public static class CSVContentGenerator { ...
David Klempfner's user avatar
0 votes
2 answers
187 views

Get records from Generic Object using LINQ C#

I have generic object and I need to get item {code, description} from it using LINQ Query Class [Serializable] [XmlRoot("Genders")] public class Gender { [XmlElement("Genders")] public ...
K.Z's user avatar
  • 5,393
0 votes
2 answers
2k views

LINQ anonymous object is inaccessible due to its protection level

I have LINQ logic that collects regex parsed data into a dynamically-created dictionary. The issue I am facing is accessing the data in the dictionary (Info). Regex .Matches(text, pattern, ...
user2219930's user avatar
0 votes
1 answer
290 views

Observable.Create doesn't work and Observable.ToEnumerable blocks indefinitely

Why the code below doesn't work? var observable = Observable.Create<int>(o => new Action(() => { o.OnNext(0); o.OnCompleted(); })); foreach (var item in observable.ToEnumerable())...
Ryszard Dżegan's user avatar
0 votes
1 answer
143 views

Dynamic LINQ statement

I am trying to query database using EF and LINQ. I have multiple queries to filter data based on user permissions with in the application. from p in db.EmployeeDetails join i in db.EmployeeDept on p....
user3731783's user avatar
0 votes
1 answer
93 views

How to iterate through a list and while iterating, iterate through another list and replace values for upper list with inner list key value pairs

Ok what i want is simple but i could not write it properly I want to replace each value of a string list with multiple values (another list hold this values). I can write several loops however i want ...
Furkan Gözükara's user avatar
0 votes
2 answers
542 views

Linq results to a var does not populate values unless refreshed manually

I have this code fragment which returns specific records from a dataset. DataTable tblr = new DataTable("itemsToValidate"); tblr.Columns.Add("Position", typeof(string)); tblr....
TonyP's user avatar
  • 5,751
0 votes
1 answer
2k views

Displaying multiple rows in a single View using Details Scaffolding [closed]

i have an employee details table, where i have a column called Role. Each employee can have more than one role. Currently following is the recordset that I am getting from SQL which i want to display ...
Ajay Sutar's user avatar
0 votes
1 answer
66 views

Tranform and Apply Expression via LINQ?

I am looking to support "expression passthru" as follows: public IFastIndexingCollection<T> { // Main data structure here = // Key = property name // Value = class below private ...
debracey's user avatar
  • 6,547
0 votes
1 answer
88 views

Linq join and count gives me an error... don't know why c#

I'm using asp.net web forms 4.5 I'm trying to join two tables products and lots by var query = _cc.products.Join(_db.lots, p => p.parentLotIndex, ...
Jinmo Chong's user avatar
0 votes
1 answer
148 views

Which extension method is used when indexing into IEnumerable [duplicate]

When indexing into an IEnumerable, I've noticed that using an index that is out of range will result in a default value being returned. I would have expected to receive an ArgumentOutOfRangeException. ...
Jason Tyler's user avatar
  • 1,359
0 votes
2 answers
80 views

complicated mvc linq generated sql script

I am pretty new to MVC world, but I been doing asp.net for years now. I started this project with mvc so I can get used to it. I been struggling some overly complicated sql statements linq has been ...
drewex's user avatar
  • 317
0 votes
1 answer
1k views

Index (zero based) must be greater than or equal to zero and less than the size of the argument list in ef 5.0 query

I have code-first based context with following entities: public class City : IEquatable<City> { public City() { Posts = new List<Post>(); } public City(string ...
Rudolf Dvoracek's user avatar
0 votes
2 answers
1k views

LINQ to Swap few Columns to Rows of a DataTable using C#

I've datatable: location Quarter ppl_required ppl_available BLR Q1 70 35 BLR Q2 50 45 BLR Q3 25 28 BLR ...
venkat's user avatar
  • 5,678
0 votes
0 answers
36 views

How to modify treeBuilder.Dot to generate LEFT JOIN instead of INNER JOIN in custom function generator for NHibernate?

Im trying to extend LINQ to NHibernate provider for my custom function. The problem that I found is that, whenever I try to access a FK from my entity, it generates a "INNER JOIN" statement, ...
Pretors's user avatar
0 votes
1 answer
79 views

Pick elements from list based on a selection criteria which involves previously selected element

I have a list with numbers which are actually distances, say 0.4,1.2, 5.6,7.8,8.9,10.2, ..... 10000.25. Now I would like to select every element from this list such that the distance between each ...
user2822838's user avatar