get the account in the linq query

i want to get count in linq query its work fine without comparing date in where condition but after comparing date it gives exception. public static IList GetAllCategoryData() { using (var objEntity = new BlueCouponEntities()) { return (from TBL in o

Foreach statement takes long

I have a foreach statement inside another foreach statement that is taking a really long time to iterate through. (There a lot of records). Is there a way to simplify this code? Perhaps with Linq? Here is my code: IList<SourceCounterPartyExposure_Lim

Convert this list of objects to json using LINQ

I am trying to convert some data into a json object that HighCharts library is expecting for its series data. This is the format: var series = [ { name : "Duplicate Transactions" data : [190, 107] }, { name : "Unique Transactions" data

Console.Title c # current time

I am making a tetris program in c# and i would like to represent the remaining time in the title of the console. Why does this not compile? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.T

How to set up a nested repetition?

With this code i can set up with for, where i select a number of rows and for each row the character + increases. But i do not know how i can program it to display on the first row the amount of + but on the second row and so on variable n asigned fo

In the sql query to linq query clause

If someone could help me to write the following query in Linq, help would be highly appreciated. select totaldue from Receivables where studentid = 8128 and reportedon = (select max(reportedon) from Receivables where studentid = 8128 check this: var

Filtering Entity Framework Data

I have simple method where I retrieve data from database and send it to the View. But in the meantime data need to filtered. I have below code: public ActionResult Index(string Name, string Manufacturer) { var dev = db.Devices; if(!String.IsNullOrEmp

Why do I have the error message: attribute doubled?

why do I get here the error message: Doubled Attribute? I guess this means, there are more than one Attributes with the same name and value. XElement XMLRun = new XElement("RessourceAttribute"); foreach (var kvp in Run) //kvp = KeyValuePair<s

Linq to entity - dynamic query

public void ApproveRowTable(string tablename, List<int> idValues) { foreach (var x in idValues) { var context = new SSPModel.sspEntities(); var genRules = (from a in context.GeneralRules where a.ID == x select a).SingleOrDefault(); genRules.Approved

Using the LINQ nested query to get the latest rows to update

LINQ experts, I am looking to update the latest data on a per user basis, to explain say I have a table "dummy": CREATE TABLE [dbo].[dummy]( [Id] [int] IDENTITY(1,1) NOT NULL, [TimeStamp] [datetime] NOT NULL, [UserId] [int] NOT NULL, [TransAmoun

How to handle exceptions using the LINQ SubmitChanges method?

I am adding a new record to my department table using LINQ, this what I do: try { dpt = new departement(); dpt.departementcode = tbDepartementCode.Value; dpt.departementname = tbDepartementName.Value; dpt.createby = "hendra"; dpt.createdate = Da

The sequence contains no elements - LINQ, MVC, Average

I am running into this error. I see that the reason is because the average returned at times is 0.00 which from a data stand point is accurate. This SQL query works fine, but that is because it puts in 0.00 automatically. LINQ complains and so I trie

Deep LINQ projections, how?

Let's say I have a model created with EF 4.0 User Roles Permissions Each entity has a DeleteDate property. I want to get a specific user (with Name =...) and have the tree filled with items where DeletedDate == null.. This must be done with anonymous

Include the referenced table via LINQ under MVC3

How I can use Include of the LINQ properly under MVC3? I created .edmx file and it has all tables. Two of them have a relashionships UserCategories 1..0 - * Users I guessed to use var userCategories = db.UserCategories.Include("Users"); in order

EF null check on group by clause

I need the following code to work on any IQueryable, even if the underlying repository is just an array. This throws an NRE during my unit test with a fake in memory array backing store. Obviously because y might be null, especially after a left oute

sequence operators not supported for 'system.string' type

what is the problem in this query var ptypes = (from mf in _pagecontext.PagesRefs let a = mf.nvcr_Slug.Substring(mf.nvcr_Slug.LastIndexOf("/") + 1) // gets everything after / let b = Regex.Replace(a, @"[\d-]+$", m => m.Value.Replace

Analyzing XML files using LINQ

i need to pull data out of an xml file based on certain field values. the xml file is set up like this <main> <report> <version>1.0</version> <ID>1234</ID> <field> <acel>80</acel> <decel>50</d

How to improve the performance of LINQ to EF

I have two classes: Property and PropertyValue. A property has several values where each value is a new revision. When retrieving a set of properties I want to include the latest revision of the value for each property. in T-SQL this can very efficie

Content of a tag in linq in xml

Im trying to get the content of a tag using linq to xml. I cant seem to get it to work. Any help would be apreciated. <BTMACRequestResponse xmlns=""> <BTMACRequestResult xmlns:a="http://wholesale.f

How can I get sql query Equivalent to a linq expression

How can i find out when my program execute a linq expression what sql query has been executed?Profiling is a sure way. Depending on the LINQ provider, this may also be inbuilt, for example with LINQ-to-SQL you can assign anything to .Log and it will

IEnumerable & lt; T & gt; Contains a predicate

I need just to clarify that given collection contains an element. I can do that via collection.Count(foo => foo.Bar == "Bar") > 0) but it will do the unnecessary job - iterate the whole collection while I need to stop on the first occurren

Extract an SQL query from LINQ expressions

Is it possible to extract sql statements from LINQ queries ? Say, I have this LINQ expression. string[] names = new string[] { "Jon Skeet", "Marc Gravell", "tvanfosson", "cletus", "Greg Hewgill", "Jar

Multiple or unique repositories with LINQ

I've been reading Chapter 11 (Testable Design Patterns) in the Professional ASP.NET MVC 1.0 book. In the examples in this chapter, data access is split into a number of repositories: IOrderRepository, IProductRepository, etc. That all makes sense: a