.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

Linq qry with order by basic questions

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

I have never tried a group by with linq, now I do and I'm stuck.

I try to convert this sql statement to its linq counterpart :

SELECT COUNT(tb_Mailer_Smses.Id) AS [cnt], tb_Mailer_mailing.Id As [Id]
,SUM( CASE WHEN tb_Mailer_smses.DLRStatus = 200 THEN 1 ELSE 0 END) As [Delivered]
FROM tb_Mailer_mailing INNER JOIN
tb_Mailer_Smses ON tb_Mailer_mailing.Id = tb_Mailer_Smses.MailingId
WHERE tb_Mailer_mailing.ApplicationId = 1
GROUP BY tb_Mailer_mailing.Id

Is there some one who can me show me the convertion process ?

View Complete Post

More Related Resource Links

Basic Instincts: Increase LINQ Query Performance


Jared Parsons demonstrates a technique to achieve maximum performance from LINQ queries on large sets of data in order to create a responsive user interface.

Jared Parsons

MSDN Magazine August 2008

Map LINQ: Create Dynamic Maps with Visual Basic 9.0 and WPF


Scott Wisniewski uses Windows Presentation Foundation data binding along with LINQ and new XML features in Visual Basic to build an interactive app that maps demographic data.

Scott Wisniewski

MSDN Magazine December 2007

Questions on inserting to Linq to Sql

I have a situation that I can't figure out.  Say I have tableMain, and tableSub.  Say I have an association in the dbml between tableMain and tableSub such that tableMain is the parent class and tableSub is the child class.   I can't insert any records programmatically into tableSub.  I get a "Specified cast is not valid." error.  If I remove the association and run the exact same code, the record is inserted without a problem.This has been an issue for me for some time.  I've resorted to haveing a second dbml to use when inserting records into tables with an association with my main table, but I don't like having tables in more than one dbml unless it's really necessary.  It's too easy to forget to update a dbml when changing a table structure.Does anyone know why this is happening?

I have some basic questions on InArgument

1. What is the purpose of the InArgument as opposed to a standard property? 2. If I have no intention of holding an expression in the argument should I just use a standard property? 3. When I write my activity to XAML, will it serialize standard properties' values? And deserialize them coming back? 4. Would InArgument<FlowDocument> be weird? And in that circumstance, is it possible to bind directly to the FlowDocument from my designer?

WCF DataService : basic Order - OderDetail - Product use case - unable to persist

Hello, I have the very classical Order - OderDetail - Product use case. I've made my database, my entity framework model and exposed it as a DataServices Read/Write. Order, OrderDetail and Product table have a Id column which is a PK based on an IDENTITY column (auto incr) Form the client, I try the following : MyEntities session1 = new MyEntities(svcUri); Order o = new Order(); session1.AddToOrder(o); o.OrderDate = DateTime.Now; Product p1 = new Product(); session1.AddToProduct(p1); p1.ProductDescription = "Product1"; Product p2 = new Product(); session1.AddToProduct(p2); p2.ProductDescription = "Product2"; OrderDetails d1 = new OrderDetails() {Product = p1, Amount = 1}; session1.AddToOrderDetails(d1); o.OrderDetails.Add(d1); var response1 = session1.SaveChanges(SaveChangesOptions.Batch); I receive the following error : Unable to determine the principal end of the 'MyEntities.FK_OrderDetails_Product' relationship. Multiple added entities may have the same primary key. I try to initialize every Id (PK)  of every object I create on the client using temporary values (-1,-2,-3,...) and then I got an other error message : The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_OrdeDetails_Order\". The conflict occurred in database \"MyEntities\", table \"dbo.Order\", column 'OrderId'.&a

Help on basic Linq query

i have this model of my payroll systembut i can't query from my employee, i mean can't fetch the data in employee so that i can manipulate the data to compute the payroll Employee employee = new Employee();           var query = from s in employee  where employee.EmployeeId == payslip.Employee.EmployeeId select employee.Rate;           decimal rate = query.FirstOrDefault(); Employee employee = new Employee();PaySlip payslip = new Payslip()Uploaded with ImageShack.us          var query = from s in employee  where employee.EmployeeId == 1 select employee.Rate;          decimal rate = query.FirstOrDefault();but i get this error could not find an implementation of the query pattern for source type 'PayrollSystem.Models.Employee' 'Where' not found.when i research other references their code always has this DataContext db = new DataContext(); i do not know how to declare datacontext help anyone?

where do basic SQL questions go?


where do basic SQL questions go?

and what does SSIS stand for?

Basic Security Questions



I'm new to ASP.NET, so please excuse my stupid questions^^

I have already done many tutorials but i don't understand how to work with that membership thing.

If I click on my project and select ASP.Net Configuration I can Setup Users, Roles and so on. But where do they get saved?

How does this ASP.Net Configuration behave after the page goes live, i don't want anybody who knows the adress of this "backend" to access it.

Many Questions, perhaps easy answers...

Maybe you have a good tutorial for me, beacause i didn't find one that explained the whole security subject to me.



Linq questions


Hi. I'm currently building application using linq. I am little bit confused on using different types of linq.

Which Linq is better(2Sql, 2 enteties, etc.)? And why?

1. How i choose right type of linq?

2. .dbml file is used only for linq-2-sql? how do I access data while using linq to entities (I mean there is no data context required, right?)?

3. Is it possible to submit value to child table using something like: db.Table1.Table2.Column = Value?

4. I have table with 3 columns: ID, Value, ForeignKeyID. I want user to be able to add as much values to this table as he/she wants. What control do I use on client side? Gridview? or dynamically generated textboxes?

Thank you very very much!

Linq Question - Calculating Value for Order By



I have a class that I have written to calculate distance base on Lat/Lng. In my linq I need to calculate this distance and order by it. Something along these lines?

 IEnumerable<TheEntity> data = from ent in entities.TheEntitys
                                                  let geo = new GeoHelperClass()
                                                  join loc in entities.TheEntitysLocations on ent.ID equals loc.EntID
                                                  orderby geo.CalcDistance(loc.Lat, loc.Lng, reqLat, reqLng)
                                                  select ent;

This is what I origanally thought of but clearly not.

Any help on this would be apprechiated.


Linq Order By ... Aggregate


Hello, i have a database with an Image table and a Rating table that holds users rating from 1 to 10.

I have the final result stored in a List(Of myDatabasemodel.Image) and i want to sort it with highest ratings first.

I can probably do it in some clumsy hard way with alot of loops but i think i should be able to it with the .aggregate function. The problem is i cannot figure out how and i need some help.

finalSource = From _image As myDatabaseModel.Image In tempSource
                     Order By _image.RateImage.Aggregate(???)
                     Skip _skip Take _take
                     Select _image

LINQ interview questions

LINQ interview questions
LINQ# INTERVIEW# QUESTION is the acronym for Language Integrated Query. It is a collection of standard query operators that adds native data querying facilities to .NET framework Languages like C#, VB.NET# LINQ is used as a medium to fulfill the gap between the world of objects and the world of data.

Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend