Get Data From Two Tables With Linq And Return Result Into View

Mar 5, 2011

I have two tables: Projects and ProjectsData and I want to execute query with join and get the result in the View. In the Controller I have this code:

ViewBag.projectsData = (from pd in db.ProjectsData
join p in db.Projects on pd.ProjectId equals p.ID
where pd.UserName == this.HttpContext.User.Identity.Name
orderby p.Name, p.ProjectNo
select new { ProjectData = pd, Project = p });

What I should use in the View to extract this data. I tried that:

@foreach (var item in ViewBag.projectsData)
{
@item.pd.UserName
}

but it doesn't work.

View 1 Replies


Similar Messages:

Get Data From Two Tables (join) With Linq And Return Result Into View?

Mar 4, 2011

I want to get data from Projects(which have CourseId) and related CourseName from Courses table.

I have written following code:

var projects = from n in db.Projects
join c in db.Courses on n.CourseId equals c.ID
orderby n.Name
select new { Project = n, Course = c };
return View(projects.ToList());

and I get error:

The model item passed into the dictionary is of type 'System.Collections.Generic.List1[<>f__AnonymousType22[ProjectManager.Models.Project,ProjectManager.Models.Course]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ProjectManager.Models.Project]'.

What I need to do in Controller and in View to display this data?

View 2 Replies

Forms Data Controls :: Displaying Correct Result Inside DropDownList From LINQ Query Result

Jul 1, 2010

I have this ListView that has a Drop Down List.Everything works fine (I think/hope) except that the drop down list are not showing its result correctly.This is the code.

Front-End
[Code]....

The code behind consist of the page_load and the ItemDataBound
[Code]....

View 3 Replies

MVC :: How To Pass Linq To Entities Query Result To View

Apr 1, 2010

i have a new question: i read all the tutorials that i found but i cannot understand how to pass a result of a linq to entities result to the view so that i can display the results. My query is actually in the controller function ot the view, i would now loop the results and display them in the page. How?

View 23 Replies

C# - Cannot Return Proper Model Into View When Doing A Join Linq Query

Mar 18, 2011

I have this code in my controller:

public ActionResult Index()
{
MembershipUser currentUser = Membership.GetUser();
Guid UserId = (Guid)currentUser.ProviderUserKey;
using (var db = new MatchGamingEntities())
{
var MyAccount = from m in db.Accounts..........

I want to be able to do a join query between my two tables Accounts and BankTransactions. This is a one to many relationship, there can be multiple BankTransactions per Account. I want to query this and display the account information including all the bank statements that are associated with it. I did a join in order to get it, but I am having trouble handling the model. I keep getting this error:

LINQ to Entities does not recognize the method 'System.Collections.Generic.List1[MatchGaming.Models.BankTransaction] ToList[BankTransaction](System.Collections.Generic.IEnumerable1[MatchGaming.Models.BankTransaction])' method, and this method cannot be translated into a store expression.

View 2 Replies

Linq To XML - Getting Correct Query Result, But It's Buried Deep In The Result Var?

Mar 1, 2011

I'm having a problem with my Linq to XML query. I'm getting the result data I want, but it's nested so deep that there must be a better way.Here is my XML:

[Code]....

I'm trying to get a list (simple string[]) of all Item IDs where Category Names contains "Other".Here is my Linq:

[Code]....

[Code]....

Here is a snapshot of my result from Visual Studio:The results I want are there ("item100", "item400", "item500"), but buried so deeply in the results var.

How can I get the query to return a simple

string[] = { "item100", "item400", "item500" }

View 4 Replies

Data Controls :: Search Multiple Tables In Database And Display Result In GridView?

Apr 5, 2014

I want make a search by which want find data and display in gridview.

View 1 Replies

SQL Server :: Return Joined Data From Two Tables?

Dec 6, 2010

I know this has to be easy. I'm just not sure of the best method to use. Should I be using ViewData?

Table 1 has columns:

ID
Name
TypeID

Table 2 has columns:

TypeID
TypeDescription

The tables are linked by a key on the TypeID column. I want to display:

Table1.ID
Table1.Name
Table2.TypeDescription

View 3 Replies

Forms Data Controls :: How Do Paging In Gridview With Sql Full Text Search Return Result

Feb 13, 2010

i know how do the paging with normal return query using row number in sql server, but i'm looking how to do the paging , sql server full text search returning result.

Can i use the same row number function or any good perfomance way?

whcih sql server full text search(FREETEXT,CONTAINS and etc) is best article site?

View 3 Replies

DataSource Controls :: How To Get Data From Two Tables In Linq

Apr 28, 2010

How to get data from two tables through linq .1 ) productsDetails 2) productsImages to bind further listview.

View 1 Replies

Databases :: Trying To Figue Out Groupings On Data Tables With LINQ?

Feb 15, 2010

I am having a hell of a time trying to figue out groupings on data tables with LINQ. I am using VB

I have two data tables. I'll define from Table Law = columns (ven_grp,comp_no,acct_unit,description,company)

Table Comps = columns(comp_parent,comp_struct1, comp_struct2, .... through comp_struct9 Now here is the SQL equivalent of what I need in LINQ

[Code]....

For reasons I won't get into I can't use SQL to do what I need to do. this is how far I got with LINQ

[Code]....

which works ok, but I can't for the life of me figure out how to group on the fields I need to and then dump the query results into datatable. I've looked at tons of examples on line and I just don't seem to get it or it does not work the way examples show. Both of my tables are defined as similar "Dim law = ds.tables(0).asenumerable()

View 1 Replies

MVC Return Json Result?

Feb 4, 2011

I have a controller that uploads a file. I would like to return a json result with bool success (if successfully uploaded otherwise false) and message (this could be error message that occured OR link to a file OR link to an image, depending on what was uploaded).What's the best way to approach thisI have this

public class UploadedFile
{
public bool Success { get; set; }
public string Message { get; set; }
}

then In my controller I would set Success to true/or/false and Message to <a href OR <img am i on the right track?How would i then parse this in the view so that when image it will show an image, if link show a link, if error simply alert error.

View 2 Replies

How To Give Data Reader Result As Source To Grid View

Sep 4, 2010

when i found datareader object containing data after execution of query

simply giving gridviewdata=dr;

does not work

View 1 Replies

Forms Data Controls :: Customized View In Paginating XML Result?

Jun 13, 2010

I have an application as in the following,

[Code]....

The application works, but I would like to have 10 results per page. How easily can this be done? I don't want to use data view or grid view like most of the examples talk about, I would like to do this in the fashion that looks like what I have now, only not so many entries in a whole page.

View 3 Replies

DataSource Controls :: Deleting Data From The Multiple SQL Tables With LINQ (C#)?

Apr 22, 2010

I'm looking for ideas on deleting data from the multiple SQL tables with LINQ (C#).

My existing solution does the following:

1. DeleteAllOnSubmit( Subset of the data from the child table)

2. DeleteAllOnSubmit( Subset of the data from another child table)

3. DeleteAllOnSubmit( Data from the parent table)

4. CommitChanges()

All this resides within a single method, which makes it ugly and not re-usable.

I have considered the following alternatives, but I decided not to use them:

1. Cascade delete on the tables.

2. Do a join on all tables from which I will remove the data, but I'm not sure yet whether I could pass a join query to DeleteAllOnSubmit().

3. Write stored procedure(s) to delete data from each table. I don't have the time to implement this due to a large number of tables and the time constraints.

View 1 Replies

Data Controls :: Display Data From Multiple Tables Using LINQ To SQL In MVC

May 7, 2015

I have to display records from two tables where foreign key table contains many values for a primary key column how to get the data using linq query???

View 1 Replies

ADO.NET :: Retriving Data From View . Linq To View C#

Mar 10, 2011

Hi to All,



I would like to ask for advice how can i load the data and the columns from MSSQL View to my app by View name.

Let say i have one methode/class that gets the view name and returns back the data (List<Object>).

And in the xml mapping i can set the relation between the object and the columns in the view.



Any advice will be appriciated.



Thank you



Ori







View 3 Replies

Data Controls :: Compare Two Data Tables Without Using LINQ

May 7, 2015

I want to compare two data tables to find out any idetical row are there, and my project not support linq ...

View 1 Replies

MVC :: Create A DraftResult Class In Order To Show Data That Resides In Two Different Tables Using Linq

Aug 9, 2010

The problem is I had to create a draftResult class in order to show data that resides in two different tables using linq which means if i want to add or remove a column i will need to do so in the draftresult and in my linq. Here's what my setup looks like: I have two tables (draft, lookUpStatus)

draft table columns
idname,status id
lookupStatus
idtitle
public class draftResult {
public string draftName {get; set;}
public string status {get; set;}
}

I want to list the draft name and the status title in a table view. In order to do this, I wrote the following linq in a method in my sqlRepository class and return it to a IQueryable<draftResult>. My controller instanstiates the sqlRepository object and invokes GetDraftListing().

public class sqlRepository {
private Table<Draft> _draft;
private Table<LookUpStatus> _lookupubStatus;
public IQueryable<draftResult> GetDrafLtisting() {
return (from draft in _draft
join status in _lookuptatus
on draft.StatusID equals status.ID
select new draftResult
{
draftName = draft.name,
status = status.Title
});
}
}

The above process works but does not seem as flexible and i'm trying to get a better understanding of MVC and LINQ.

View 8 Replies

DataSource Controls :: How To Check Two Queries Return Result Is Same

Feb 26, 2010

how to wrote stored procedure for check two queries result this result is same return true value its not same return false value

View 2 Replies

Web Forms :: Return Integer Result From Store Procedure

Feb 21, 2012

I want to return integer result from storeprocedure.I have used dataset to return values.My store procedure which i have wrotewhich return three result 0,1,2I want to get this result..how to get that result.

View 1 Replies

MVC :: Get The Data From Join Tables In The View (Razor)?

Mar 5, 2011

I have two tables: Projects and ProjectsData and I want to execute query with join and get the result in the View.

In the Controller I have this code:

[Code]....

What I should use in the View to extract this data. I tried that:

[Code]....

but it doesn't work...

View 2 Replies

MVC :: Display Single View Data From Two Tables?

Apr 26, 2010

how can I display on a single page(View) data from two tables in my db? In my project the model is *.edmx file. i have two table one with categories, and the second one with products. All I want to do is to display on home page(view) in left column all categories, and all products in right column. After clicking on category in left column, in right column there should be products form category which was clicked....

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

Display Data From Multiple Tables In A Single MVC View?

Nov 30, 2010

I am having a hard time solving the following with an MVC view. My goal is to display data from multiple tables in a single MVC view. The bulk of the data comes from a table called Retailers. I also have another table called RetailerCategories which stores the retailerid from the Retailers table and also a categoryid linking to a Category table. Note that there are multiple records for each retailerid in the RetailerCategories table.

In the view I want to show a list of retailers and with each retailer I want to show the list of categories applicable to them. What would be the best way to accomplish this?

View 2 Replies







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