I have the following line: orderBaseData.Single(o => o.Id == order.Id).OrderMessages.Count; I want to filter this a bit more. Each OrderMessage has a variable called hideFromUser, and I want to get the count of the OrderMessages where this is set to
Please help me to convert this SQL statement to Linq in C#: string cmd = "SELECT * FROM dbo.Personnel WHERE (dbo.Personnel.FName LIKE @FName + '%' AND dbo.Personnel.LName LIKE @LName +'%')"; if (objPPersonnel.PersonnelCode != 0) { cmd += "A
I have a query which gets an employees number from a field containing their username and employee number in a field like this: name [employee number] e.g. Fred Bloggs [1234] My query works fine most of the time, but occasionally the field does not co
I have a data table, which contains set of Attributes like (First Name, Last Name, Gender etc..) I wanna count the occurrence of value in only two columns or Attribute. For example, I have 4 columns in my datatable (FirstName, LastName, Age, Gender).
I've a supplier table filled with supplier objects, supplierID is the primary key here. I've to find all products supplied by these suppliers. Since there is a many-many relationship, I've a bridge table in between SupplierProducts, with supplierID a
I have article and author classes. Fetch articles like so and map entity to model: public List<Model.Article> GetArticleList() { using (var db = new ArticlesContext()) { return db.Articles.Select(t => new Model.Article() { Author = MapUserEntityT
I want to use a pre-loaded lookup data from a list within a query. I need the query to return as IQueryable because it is used in a grid & being paged (not included here). I need the Labels to load from the lookup to avoid joins (more are in the actu
I am modifying my project to use DBContext instead of ObjectContext. My existing code var query = context.Vehicles.OrderBy("it.VehicleType.VehicleTypeID"). GroupBy("it.VehicleType.VehicleTypeID", "Min(it.ODO_Reading) AS MinRunVehi
I have a database table with a field defined in a very simplified form like that CREATE TABLE Product ( ProductId INT, Price SMALLMONEY ) I have a LINQ entity framework query that in it's simplified form goes something like: Iqueryable query = from P
i have the following code to determine a age from a Person var pList = ctx.Person.Where(x => x.Create > Date); int Age = pList.Where(x => x.ID == "foo").FirstOrDefault().Age ?? 20; I pick a Person by ID, if it doesn't exist the default
I try getting all the Xelement value and insert into an array, however when the Xelement is null, it will show the error as below when insert into array: Object reference not set to an instance of an object. Is it possible to remove the null value? O
Workign on xml reorder My XML is as follows: <Subjects> <Subject> <Name></Name> <Height></Height> <Addresss> <Address> <City>AB</City> </Address> </Addresses> </Subject> <Sub
I have 3 tables, Person | Book | PersonBook PersonBook table is relaton table between Person and Book Person Book PersonBooks Id Name Id Name Id PersonId BookId 1 rick 1 SQL 1 1 1 2 phil 2 Asp.Net 2 1 3 3 scott 3 MySql 3 2 4 4 C# 4 3 2 5 3 3 6 3 4 I
I am trying to write a method which will ultimately give me a collection of records which no longer have a corresponding record within a different collection to which I am referencing. The structure is something similar to: public class A { int id {g
I have the following xml string that I am attempting to query into a datatable based on a dynamic set of columns. I do not have any control over the xml, it is being passed in from an external source. XML: <VmapMessage> <MessageBody> <Claim
This question already has an answer here: How to use LINQ to select object with minimum or maximum property value 11 answers I have a class like this class car { public string carName { get; set; } public decimal price { get; set; }//Group id } I hav
I am attempting a LINQ query in a VB.NET WPF solution that bridges two datatables and groups by a Zone. I am receiving an "Invalid Cast Exception" on these rows: .MfstCt = ZoneGroup.Count(Function(c) c.Field(Of String)("ConsignmentNumber&qu
I have an incoming array with a count per row and a string which represents one or more key's split by underscore. for each key I'd like to group and sum the total where if the key appears in a row with a total of 5, each item split by the underscore
I don't understand why code A is correct and code B is incorrect: code A IEnumerable<decimal> loanQuery = from amount in loanAmounts where amount % 2 == 0 orderby amount select ascending amount //this line code B (incorrect) IEnumerable<decimal&g
I have to populate below class in Linq Query public class Emp { public string name {get; set;} public dynamic Obj { get; set; } public Emp() { Obj = new ExpandoObject(); } } public LoadData() { var emp = (from d in dbContext.Employees select new Emp
I'm fairly new to programming but have been tasked with maintaining some applications that were created by a previous employee. I have a ?: statement that now needs to handle more than a true or false statement but I'm not sure how to go about doing
Actually, it is a closer duplicate of: RemoveAll for ObservableCollections? Possible Duplicate: using LINQ to remove objects within a List<T> This is the code I'm using, but its not very readable. Can I use LINQ to shorten the code below while still
I want to create a GridView that displays records for PDF Files. These records can have meta data attached that is customizeable by the user, so they can create their own columns and enter their own information in there. I then want it to be displaye
I stuck in an easy scenario. I have a List<string> object, all of its items has the body of: item_1_2_generatedGUID //generatedGUID is Guid.NewGuid() but there may be much more numbers item_1_2_3_4_5_generatedGUID etc now, I'm wondering how to chang
Today i ask this question, but i missed something so ill describe more in this question. I have three tables: [Table1] - ID // Unique - Name - Location - Country [Table2] - ID - Unique - Table1.ID - Value [Table3] - Table2.Value - LN - Name Relations
I try to get first character occurrence in text keeping their original order. I try to use LINQ but I'm very new in this, so something is wrong, and I have bad result. For example I write: "languages", so the result would l-0, a-1, n-2, g-3, u-4
Okay, so I'm new to both EF and LINQ. I have figured out how to INSERT and DELETE but for some reason UPDATE seems to escape my grasp. Here is a sample of my code: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", Ge
I have list of ints consisting of {1,2,3,1,2,1,5,1,2,1,1} I like retrieve all 1 located before 5 . I need skip all other items after 5 .The End list will be {1,1,1} How can i do this using linq?Try this: using System.Linq; class Program { static void
I have been following along with Rob Conery's Linq for MongoDB and have come across a question. In the example he shows how you can easily nest a child object. For my current experiment I have the following structure. class Content { ... Profile Prof
Why only one overload throws this exception? Little update: I understand that there was a design decision made by framework developers. The question is really why that decision has been made, is there a related design pattern or whatever? Because if