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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

LINQ Sorting After Goup w/ Table Reference

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

Having a little trouble here.  I am taking a table (Articles) and grouping all the results by the key that references another table (ArticleSectionCategories).  I then want to sort these results by the OrderBy field of the referenced table (ArticleSectionCategory.OrderBy).  This is what I am using right now but it is not working.  Any thoughts?


                var GroupedArticles = from A in DC.Articles
                                     where A.PackagesId == packageId
                                     group A by A.ArticleSectionCategoriesId into G
                                     select G.OrderBy(C => C.ArticleSectionCategory.OrderBy);


View Complete Post

More Related Resource Links

How we Update DataContext's Table Implicitly in Linq using .Net 3.5..?

Hi All.. My problem is i am working on Linq,as we know to use any table in linq we have to drag and drop it on our datacontext's Designer File,and at run time we got its value,till here no any problem,main point is if any changes in respective data source's schema has made ,then on datacontext we will not get that changes,for it we have to change this datacontext manually by by again drag and drop,it will not happen implicitly when this changes has been made on the data source. so please tell me how i solve this problem so that datacontext change implicitly without any over head  using .net 3.5 . 

application role how query a view whose reference table is in another db?

Hi everybody. I created  an application role in a database (DB1) and gave it all the rights on a view  in DB1 which refers to a table located in another db (DB2).  I also gave the rights to the app role on a table of  DB1 I tried to use this app. role through the sp_setapprole launched by a user  (server principal?) which is SQL Server administrator (and local administrator (Win 2003 Server)). With the following query SELECT USER_NAME() I see that the approle is being used. Than, if I query the table on DB1 everything works, but if I query the view, referring a table in db2 I get following error:   The server principal "NameOfServerPrincipal" is not able to access the database "DB2" under the current security context. What should I do to make it work? The table in DB2 has the same schema of the view in DB1 which refers to it. I put the DB1 TrustWorthy and both the database have the db_chaining option activated.   Any idea on how to solve the problem would be widely appreciated. Thank you very much. Vania

dynamic table name linq-to-sql query


I am writing a function in which i generate autocode in specific format i want to make this function generalize so that i send tablename and columnname  parameter and function return the next code. I am using linq to sql with MVC e.g. i want to make table name and column name dyanamic

from m in db.<tblnameparam> 
                       orderby m.<colnameparam> descending
                       select m.<colnameparam>

Is pivot table alias an internal reference?


What is the purpose of requiring a table alias for pivot table if it is for internal reference only?

LINQ to Entity - using join for multiple table


I have my SQL query which needs to be conerted to Linq to Entity,

select pfr_sa.SID,pfr_sa.SourceGroupID,tx.txroll_cadaccountnumber,tx.txroll_StreetNumb

Can a table name impact generating the service client when creating Service Reference?


I have a new WCF service I'm writing under VS2010 and IIS 7.5.  The service includes a table named Client.

When I built my test class and added the service reference, the first test was confirming the creation of the client.

My service reference did not generate any client that I could call .Open on!!!! I was wondering if it is due to that table name???

 Edited to add that I tested the service through the browser and it brings up the page and XAML fine.

Thanks for any assistance!

Junction table with Linq


Hi, I have a question about how to insert values into a junction-table with linq.

I have a class that makes all the insert/updates and delete actions, it also contains a method for submiting the changes to the database.

I have 2 tables that are connected with a junctiontable with their primary ID:s

Lets say that I want to insert some values into one of the tables. How do I in the best way insert data to the junctiontable ?

Should I lose the Save() Method and do submitchanges() in each of the methods instead?

join 3 table in LINQ



i use Default membership provider for my membership

i add a profile table for some more information from user and it related with UserId with aspnet_Users

to get data from my database i use  Entity Data Model

now i want to write a Linq to get data from all 3 tables

can you help me to know how to write this guerry



How to bind data from linq to html table without a single line of loop.




This is the above code i have worked using querysing and displaying the listitem with in  a simple html table. Here I am using foreach statement to bind items. How to bind the data to a simple html table using SharePoint linq without  a single line of loop.

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Linq;
using Microsoft.SharePoint.Linq;

namespace QuerystringProgramWithoutLoop.QuerystringProgramWithoutLoop
    public class QuerystringProgramWithoutLoop : WebPart
        string strTitle=string.Empty;
        string strStatus=string.Empty;
        protected override void Render(HtmlTextWriter writer)

Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

Adding data to table using linq to sql


Hi all, i am very new at this and are looking for some help. i have to tables, Question( Qid,question,answer,Cid ) and Category( Cid,category ), the primary keys are Qid and Cid, the Cid is a foreign key in Question, when i want to add a new question to Question i am choosing a category from a DropDownList controll, and if want to add a new category at the same time i have a TextBoks for it, i have create a Model, BLL and DAL classes, my problem is:

in the DAL class i want to add a new row to Question, but i need to check first if the object.category exsist in the table Category, if it does i want to get the Cid for it if it dosen't exist i want to create a new raw then get the Cid, this is my code: please finish my code with some explanaitions

public string add(Faq inFaq)
            using (var db = new DBClassDataContext())
                    var se = from Ca

temp table in linq

select col1,count(col2) into #temp1 from table1
where col3='asd' and code =@code
group by col1

select --------
from table2 t2
inner join table3 t3 on t2.c1=t3.c1 -----------
left join #temp1 t4 on t3.c1=t4.c1
I'm not sure how to achieve the same in the Linq.
Or is there any better way?


detele data from table with reference


I want delete data from a table but i saw this error

Msg 547, Level 16, State 0, Line 1
The DELETE statement conflicted with the REFERENCE constraint "FK_TR_BookingDetail_TR_BookingHeader". The conflict occurred in database "Master", table "dbo.TR_BookingDetail".
The statement has been terminated.

i'll try to delete data from tr_bookingDetail first, but it's still show that error.

What i must i do to delete that data?



how to work with temporry table in linq


hi everybody

how can i work with temporary table in linq i mean temporary table in temp database that creat for each table ?is it possible or i must use sql store procedure because i use linq in my project?

Dynamic Column mapping by using Reference Mapping table


Please tell me if I can create SSIS package for the below requirement:

I have source data in 2 excel files. Data from both these excel files should be loaded to the same single Fact table. The column names in excel files and table are not same. I have a Reference table which has the column mappings between excel and Fact Table.
I have to refer this Reference Tabel for column mappings, plus i have to add some derived columns (Created_Date) to load the Fact_Table.

I have given a sample data structure below:

Source Data

OrderNumber     OrderQuantity     OrderDate
Order10001             100               01-01-2011

CustomerNumber      CustomerName     CustomerAddress
Customer0001          CCPrivateLtd             India

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:
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