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
Similar Messages:
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
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
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
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
Jun 29, 2010
how can i select a record from A table and insert into B table using linq?
View 2 Replies
Mar 15, 2011
I have to find the best way to do this using LINQ. I need to summarize an amount in a iTransaction table by
Account (e.g. 12345) and add that amount to an same Account ( e.g12345) if it exists in a iAccount table . Here is the code which syntax checks ok and tested ok up to the .submitChanges statement (i.e. I stopped and didn't allow the submit.
Following is the LINQ code. (1) Is that a good way to do this. OR should I try the INTERCEPT.
(2) How is the best way to insert a new record/row in the iAccounts table if it DOES NOT exist in the iAccount Table.
[Code]....
View 2 Replies
Feb 27, 2011
I have a question about linq delete.
I have 2 table in database and they are joined.
First Table: UserID, UserName, UserSurname, UserPhone, CompanyId
Second Table: CompanyId, CompanyName
First Table I have many recods with related second table.
I want to delete one company in second record, But firtly I have to delete users (more than 1)
How can I delete it with using linq?
View 2 Replies
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
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
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
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
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
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
Dec 25, 2010
i want add a record to my table(News) in the database School.
so i create a class for news table look like this:
public class News
{
private int _newsid;
private string _datetoshow;
private string _title;
private string _description;
private string _writtenby;
public int NewsID
{
get { return this._newsid; }
set { this._newsid = value; }
}
public string DateToShow.......
pop up is:
'system.Data.Linq.Table <New>' does not contain a definition for add and no extension method 'Add' accepting a first argument of type 'System.Data.linq.Table<New>' could be found (are you missing directive or an assembly reference?)
View 3 Replies
Oct 10, 2010
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
View 1 Replies
Feb 2, 2010
In my application i want to compare data of two users from database table using linq.
lets say i have ten columns in UserMaster table.
Now based on the comparision i want to display result.
Like is 10 out of 10 columns matches for those two users result will be 100,if 9 columns matches then result will be 90 and if 0 matches thn result will be 0.
i dont want to write if else for somany time.
I am new to linq.
View 4 Replies
Dec 16, 2010
Tables:
WORKORDER and CUSTFIELD
Fields:
WORKORDER = WORKORDERID
CUSTFIELD = WORKORDERID, CUSTFIELDNAME, CUSTFIELDVALUE
There are multiple different type of name/value pairs. I want to specifically return the custfield value where custfield name is "INCIDENT", and the custfield value where custfield name is "NETWORK" all for the appropriate WORKORDERID
I've tried a few different ways and just can't grasp how the linq is supposed to go to get the results I want. I can get an incident value, or network value, but not both.
I have the proper association set up in the dbml so both of these work to get the single value:
var b = from i in edcwdv.WOCUSTFIELDs join p in edcwdv.WORKORDERs on i.WORKORDERID equalsp.WORKORDERID where i.CUSTFIELDNAME.Contains("INCIDENT") select new { i.CUSTFIELDNAME, i.CUSTFIELDVALUE, p.WORKORDERID };
var incident = from wo in edcwdv.WORKORDERs orderby wo.WORKORDERID where wo.WOCUSTFIELDs.CUSTFIELDNAME.Contains("INCIDENT") select new { wo.WORKORDERID, wo.WOCUSTFIELDs.CUSTFIELDVALUE}; So essentially i want to pull the value for each of the fields, INCIDENT and NETWORK
View 2 Replies
Jul 18, 2010
Using Visual Studio I've created a DBML file, and added a table to it from a local database. This created a data context called UserDataContext. In my ASPX page I can create an instance of the data context using:
UserDataContext db1 = new UserDataContext();
However when I try to query against the table I get to:
var query = from o in db1.
and from there I can't see the table.... the dbml shows the table has public access.
View 6 Replies
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
Feb 9, 2011
I M New to Linq, I M Searching articles using
DBSearchDataContext db = new DBSearchDataContext();
object q = from b in db.Articles
where b.Tags.Contains(val) |
b.NewsTitle.Contains(val) |
b.EnglishContent.Contains(val)
select b;
I cannot exclude results where category = video or photos. H to exclude category where value is "videos" or "Photographs"
View 4 Replies
Jan 17, 2011
I have a table created on the fly. The table structure is dynamic.
This is the table structure generated by the end of year 2010
DealerCode, 201010, 201011, 201012
This is the table structure generated by the end of Jan 2011
DealerCode, 201011, 201012, 201101
What I need to do is selecting all data and then bind it into a gridview
To build a LINQ query, we need to drag the table into dbml file first. As we don't know how the table look like, can we add it in dynamically? Are there any other solutions?
View 1 Replies
Sep 20, 2010
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
[Code]....
View 3 Replies
Mar 15, 2011
I have several tables to load from depending on a string value using Linq to Sql I currently have
[Code]....
but of course that only gets the specific table DOffices if I wanted to grab tables at runtime what would be the best way to go about it?
View 1 Replies
Jul 17, 2010
I have tables two tables, the "book" and the "author", a book can have many authors and vice versa, so there is an intermediate table called "book_author" with two columns as foreign key for those two primary keys
book_author
book_id
author_id
I'm trying to edit the book details and also its author using the entity date model, The controller class method
[Code]....
The HTML edit form
[Code]....
I can only update the book table, but not author that the book has or the book_author, I'm new to asp.net, I can't easily find a tutorial on this issue, I think the logic is to delete the author of the book first and then add the author for that book, but I don't know exactly about that linq and C# code. Can show me? I can only update the book table, but not author that the book has or the book_author, I'm new to asp.net, I can't easily find a tutorial on this issue, I think the logic is to delete the author of the book first and then add the author for that book, but I don't know exactly about that linq and C# code.
View 1 Replies