Joining 2 Lists With LINQ?

Dec 29, 2010

I'm not sure on the best way to go about this one. Simply LINQ queries are easy enough for me, but I am looking for the most efficient way here.

I have 2 tables, Sliders and SliderItems. SliderItems have a FK that points to the Sliders Id.

I have been getting information on a particular slider like this:

public static List<Slider> GetSlider(Slider sItem)
{
DBContext db = new DBContext();
if (sItem.Id != Guid.Empty)
{
var list = from tbl in db.Sliders
where tbl.Id == sItem.Id
orderby tbl.Id
select tbl;
return list.ToList();
}
}

So what I need to do for my home page is pull back a set of data that I want to stuff into a data list. Thereby combining the Slider + SliderItems that go along with it.

Do I just do a normal LINQ query with a JOIN statement and toss them into a generic list that goes back to my DataList?

View 3 Replies


Similar Messages:

Linq To Sql Joining Two Table?

Aug 10, 2010

how can i do a join in this query to another table

dynamic list = _db.Users.Where(m => m.vcr_UserName != "superadmin" ).OrderByDescending(m => m.int_UserId).ToPagedList(Cpage, defaultPageSize);

i must have a topagedList there

View 1 Replies

C# LINQ Joining And Where Statement Not Working?

Mar 5, 2010

I am trying to have the collection of order IDs be used in my where statement how come i can't get this to work?

List<int> orders = new List<int>(){1,2,3,4,5};
DataTable dtTable1 = getOrders();
DataTable dtTable2 = getOrderDetails();
var results = from a in dtTable1.AsEnumerable()
join b in dtTable2.AsEnumerable() on a.Field<int>("ID") equals b.Field<int>("ID")
where orders.Contains(b.Field<int>("OrderID"))
select a;

View 2 Replies

Web Forms :: Joining Two Data Tables In A Dataset With LINQ / Error 37 Invalid Expression Term 'in'

Apr 7, 2010

I m having one dataset underwhich i have two DataTables ie Contact & Sales Order.In this two table my ContactId field is primary key in both the tables. I cot some code similar to the following code. But when i copy this code two my .net application it me an error saying semicolun expected ,etc as shown bellow.

Error 37 Invalid expression term 'in'

Because of this i m not able to test the code. can any body tell me how can i achive it . I kust want to inner join this two tables & want to store the result in another data table.

[code]....

View 3 Replies

ADO.NET :: Left Outer Join With Multiple Tables And Generic Lists In Linq And VB?

Nov 16, 2010

I'm having trouble doing a left outer join with multiple generic lists tables. I've been researching for hours and there isn't a whole lot out there on this subject and VB (at least what I found).

I have the following Linq query:

Dim DataForGridview = (From s In S1 _
Join c In C1 On c.ID Equals s.ID _
Join v In V1 On v.ID Equals s.ID _
Select New With { _
.dataFieldID = s.ID, _
.dataField1 = s.dataField1, _
.dataField2 = c.dataField2, _
.dataField3 = c.dataField3, _
.dataField4 = c.dataField4, _
.dataField5 = v.dataField5 _
}).ToList()

S1 has a count of 30. V1 has a count of 20. C1 has a count of 10. This query joins the three but ends up with a count of only 10 based on the datakey ID and, of course, only shows those 10 in the gridview.

I would like to show all 30 from S1 in the gridview with blank fields wherever V1 and C1 do not have data. From what I've read I need to do a left outer join. However, all examples I've found are with two datasets.


I've tried multiple times expanding on what I've found by changing it to a group join and also adding the .DefaultIfEmpty() property in the query, but nothing is working.

How can I change the above query to a left outer join with these multiple tables?

View 11 Replies

MVC :: Display Data By Joining 2 Or More Tables?

Feb 10, 2010

I have prepared a web project using ASP.net MVC. I want to display data by joining 2 or more tables and on Edit performing updation in 2 or more tables.

I have 2 tables :
Employee_master(EmpID,Name,Designation)
Employee_Detail(EmpId,Address,Phone,DOB).

I am using ADO.Entity framework to create the model.I want to perform following operations.

1.Applying 1:1 association between the tables.
2.To show the information EmpID,Name,Designation,Address,Phone for all the existing records in tables on View.
3.On Selecting the Edit link want to show EmpID,Name,Designation,Address,Phone for the corresponding EmpId in EditView and then perform updation of the records in 2 tables both in Employee_master,Employee_Detail on Save.

View 5 Replies

Web Forms :: Joining Many Excel Files?

May 4, 2010

I have many excel files. How do i Join them to make just 1 file?

Like, I want the contents of 1 file below the other file and so on for all files.

View 2 Replies

ADO.NET :: Joining Archive Databases With Entity Framework?

Dec 27, 2010

I have been looking into using the Entity Framework for our project, but so far keep coming up a number of limitations trying to fit it to the way our databases are structured. Right now we are coding directly to the database through a MySQL connector, so we have full flexibility to do anything possible that SQL can handle. So the first issue I have is that I need the ability to select a different table for an Entity set at runtime, as we have some tables that have suffixes on them based on the 'brand' presented to the user (ie: shopping carts, config variables etc). I found this project on Codeplex that looks like it will allow me to easily solve that problem:[URL]

However I have another problem I need to solve. Our main database is actually re-factored into the core working set database (6 months of data), and archive databases. There is one archive database per year, where orders and other interesting stuff is archived away to get them out of the working set which keeps the database table sizes and server load down. However the problem is, every so often there are valid reasons to dip into the archive tables to pull stuff out and deal with data in the archive tables (to
refund a customer perhaps past 6 months, or to mark an order as fraud 8 months later etc, or just to query sales history for reporting). For our normal code we have structured some smart SQL pre-processing logic that allows us to find stuff across the archives and join it to the primary database. The result is a single query that returns data from either the working set, or any of the archives all at once (and can join stuff to items still in the working set, such as currently active products etc).

I have struggled to determine if there is even any way to represent that kind of thing with the Entity Framework? The schema of the archive databases is identical to the schema of the primary database, except that it only had a limited selection of tables in it (just stuff that needs to be archived). So how can we associate the main database schema with the archive tables, but more importantly be able to run a query across them all? Should I just write a separate schema for each individual archive database (or perhaps I should give up on archiving stuff by year, and just stick all the archives in one DB?)? But if I do that, is there any way in Entity Framework to join across to tables in a different database? Or for the archive database schema, to include references to tables in the main working set database?

View 1 Replies

ADO.NET :: Dynamic Or Condition From Joining Multiple Table?

Feb 14, 2011

I have to seach data from multiple table and fetch the data and from the result i have to search partical value in or condition .

Means i have 5 table from which i am fetching data and after that ihave to search multiple location means array location and from that array i have to check each location into fetch data.

View 3 Replies

SQL Server :: Insertion And Joining Data Between Tables?

Sep 1, 2010

I have the following tables:

1.) PRODUCT_INFORMATION
2.) CUSTOMERS
3.) DISTRIBUTORS
4.) PRODUCT_NAME
5.) CONTROLLER

Each table has a primary key assigned. The customers table has an ID column and a CUSTOMER_NAME column with unique index property set to avoid any duplication. How do I insert values in the product_information table that has a foreign key column from the CUSTOMERS table if we insert a value in the CUSTOMER_NAME field of the CUSTOMERS table. I want to know how can I create a join between all the tables so that when I insert values in individual tables they are joined with a serial number column in the PRODUCT_INFORMATION table?

View 1 Replies

SQL Server :: Joining Two Tables And Display Data?

Feb 23, 2011

am in problem and cant sort it out... my code is somwat lyk dis:

[Code]....

end sub

i hav joined both table..but am not able to display it in those controls.

View 10 Replies

ADO.NET :: Joining 2 Tables If Record Doesn't Exist Yet?

Oct 27, 2010

I have a table "assignments" with records that are assigned to multiple "users" by the "department" they belong to. Each user then can have it's own "status" for each assignment.

When the user logs-in i need to show all his assignments and the status.(but status record doesn't exist yet)

When a new assignment is created I don't want to have to create a new record relating the assignment to the user. I want the relationship to be by the department the user belongs to and the department the assignment was assigned to.

Only thing i can think of is when the user logs in to load the assignments that belong to the user's department then look thru all the records. For each record loop thru the status table. If a record exist show the the status. if it doesn't then make default value and when the users clicks to view the assignment a new status record will be added.

Only thing i don't like is looping thru the status records while looping thru all the assignments.

How else can I do it? I don't see how could join the assignments table and the status table if the status record doesn't exist yet.

tables:
[ASSIGNMENTS]
assignmentID
departmentID
assignment
[DEPARTMENT]
departmentID
department
[USERS]
userID
departmentID
user
[STATUS]
userID
assignemntID
status

BTW, I'm using Linq-to-SQL

View 2 Replies

Security :: Joining .net And Ruby Project Via Common Membership Provider?

Nov 8, 2010

We have a very large .net site using the sql membershipprovider offered by .net. We need to join this to a ruby on rails project - allowing login to both platforms. The ruby project shoudl be able to read and write to the .net's profile information - but additionally may store extra records against the user. The .net user record should always be the master, with logins anthenticated against this. What is the best way to open up this membership provider - via api or similar. We need something that is easy to snap into the RoR solution but secure enough and extenable enough to meet our needs. Is there some way to add on openID or similar to the .net project - and would this be what is recommended or is there a better standard to allow us to link our users.

Other features we would need to have shared are: shared email address, email verification email for both platforms. Both systems have independent CRMs and email systems so unsubscribing from these would also need to be linked preferably with an independent unsubscribe system.

View 2 Replies

Forms Data Controls :: Joining Multiple Tables To Show Results In A Gridview?

Mar 4, 2011

I have been trying to make this work for a while, but I have not been yet able to figure this put. I am using VS 2008 and mysql database. I wrote a query and checked to see if it works in database. It does.

I have a gridview, whose select command is that query. But for some reason, I just get all the rows from one table only. I rechecked my datasource and it is ok. I read on some discussions that it is NOT possible to have data from two tables in a gridview. Is that true? If that is not true, how can I have data from multiple tables in a gridview? Or any other web control for that matter.

View 6 Replies

Windows Authentication - Run Application Under Domain Account Without Joining The Domain?

Sep 28, 2010

My feeling says it's not posible but anyway I am curious if there is at least a workaround for accomplish this.Basically I am working at my client site and my machine is not connected to the domain.What I want to do is running a web application locally under a domain account, and using the webdev server.The webapp uses the default authentication, windows authentication that is.I tried using impersonation with domainuser & password but I got the following error Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.I have to mention that the username and the password are correct.

View 1 Replies

MVC :: "Latest" - Joining Models Display These In The Same Place?

Mar 22, 2011

to display my "latest updates" on my site.I have for example some photos and some journeys and reviews, these all have their own model.How do I go forward with displaying these in the same place,sorted by create date,with each having its own "look" to it.Like,photos have one template (I have a template as an .ascx already for each type) and journeys have one etc.

View 4 Replies

Security :: Impersonation With Domain Account Without Joining The Domain?

Sep 28, 2010

My feeling says it's not posible but anyway I am curious if there is at least a workaround for accomplish this.Basically I am working at my client site and my machine is not connected to the domain.What I want to do is running a web application locally under a domain account, and using the webdev server.The webapp uses the default authentication, windows authentication that is.I tried using impersonation with domainuser & password but I got the following error Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.I have to mention that the username and the password are correct.

View 2 Replies

MVC :: Really Need Help With Sessions And Lists

Dec 13, 2010

I have tried everything for weeks with this now but can't get it to work. What I'm trying to do is to store an array in a session and add numbers when a user guesses. I also have to know how to loop through the array.

Please help

[Code]....


View 1 Replies

Building DropDown Lists In MVC

Jul 21, 2010

I have an self-referencing entity which maintains a list of like entities that are it's children. What I need to do is build a dropdown that lists all possible parents so when I add or edit a new entity of that type, I can select it's parent (or no parent). The problem lies in the sql. I simply don't know how to word it.

IList<ParentForumModel> parentForums = new List<ParentForumsModel>();
foreach (Forum forum in forumRepository.GetAll())
{
// not sure how to handle this here because it isn't in the correct order. I need them to be grouped by parent and sorted by the sequence field. It also needs to be a flat dataset, not something uses IGroupedQueryable or some such.
}
ForumAddModel model = new ForumAddModel
{
ParentForums = parentForums,
// other properties
}

public IQueryable<Forum> GetAll()
{
return context.Forums.??? // what Linq do I need here?
}

If this simply isn't possible with Linq2Sql, then is there a system where it is possible? Please don't say hnibernate.

View 9 Replies

SQL Server :: Turning 2 Lists, Into 1?

Apr 1, 2011

I'm sort of new to ASP.NET. What i've done here is create a list of Newsletters seperated by University newsletters, and Alpha Newsletters. What I have now been asked to do is make these 2 lists into 1 list. I can't figure a Way to do it without designing the database? Does anyone have any ideas? Take these 2 lists and make 1? Using odsNewsletterAlpha and odsNewsletterUni to create 1 list?

<h2>University Newsletters</h2>

<asp:ListView class="lvUniversity" EnableViewState="true" ItemPlaceholderID="plcItem" DataSourceID="odsNewsletterUni"[code]...

View 3 Replies

Add Data To A Dictionary Lists In Vb.net?

May 3, 2010

I have to put data into a dictinary, thus formed: Dictionary (Of Integer, List (Of RicercaNews))

but when I go to put the list in the dictionary, I always return the same record, as if it does not increase the index of the list.

This is the code:

ResultTable Dim As New DataTable ()
Dictgestionalews Dim As New Dictionary (Of Integer, List (Of RicercaNews))
Listacat Dim As New Dictionary (Of Integer, String)
Dim listaricerca As List (Of RicercaNews)

[Code]....

View 2 Replies

Web Forms :: How To Connect Two Dropdown Lists

Sep 30, 2010

i have two dropdown lists and i would like if i select lets say "1" the second list returns "A""B" but instead it returns "A" how to make the second list display A"B when i select "1" from the first list.

View 12 Replies

AJAX :: How To Populate Drop Down Lists

Sep 27, 2010

I've been trying to get this to work for weeks. I am trying to use a cascading drop down to populate drop down lists. The service method is working as i'm able to view the data in the browser but when i run the application the drop down list is empty. see below for the service method.

[Code]....

The code for the drop down list:

Location Name:<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<asp:CascadingDropDown ID="CascadingDropDown1" runat="server"
Category="Locations"
TargetControlID="Dropdownlist3"
PromptText="[Select Location]"
ServicePath="~/LocationWebService.asmx"
ServiceMethod="GetLocation"
EmptyText="Nothing">
</asp:CascadingDropDown>

View 4 Replies

Web Forms :: AddRange Is Duplicating Lists

Feb 28, 2011

I am populating 4 drop down lists. The dropdownlists within the For loop work fine and I will ignore these for the rest of this post. Reading the code below should add 2 values to the dropdownlist ddlPost and should add 2 values to the dropdownlist ddlTailLength. Both values should be A and B. Both of these drop lists should show 2 values (A and B), but are showing 4 values each (A, B, A, B). The only loop on these pages is the one displayed below.

c#:

[Code]....

HTML:

[Code]....

View 3 Replies

How To Set Value Of Dropdown Lists In Gridview With Javascript

Oct 20, 2010

I have a dropdownlist and a gridview with a drop down list in every row. I have removed other cols in Grid for simplicity.

Whenever a new value in the dropdownlist is selected I would like to set all of the dropdownlists in the gridview to that same value via javascript. (Yea both the dropdownlist outside the gird and the ones inside the grid are populated by the same data source)

The dropdownlist:

<asp:DropDownList onchange="javascript:onJDSelection();" ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource4" DataTextField="circt_cstdn_nm"
DataValueField="circt_cstdn_user_id">
</asp:DropDownList>

The GridView:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" onrowdatabound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Change to Job Designer" SortExpression="circt_Cstdn_nm">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("circt_Cstdn_nm") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddl_jd" runat="server" DataSourceID="SqlDataSource4" DataTextField="CIRCT_CSTDN_NM"
DataValueField="CIRCT_CSTDN_user_id"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

My current attempt:

function onJDSelection() {
var jd = document.getElementById('ctl00_MAIN_DropDownList3').Text;
var grid = document.getElementById('ctl00_MAIN_GridView2');
for (var i = 1; i < grid.rows.length; i++) {
grid.rows[i].cells[0].getElementsByTagName("*")[1].selectedText = jd;
}
}

[Code]...

When clicking on the dropdown I get an alert that says "test" and an alert that says "[Object object]" However nothing happens with the dropdowns in the grid and the alert(i) never fires.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved