Solved

linq equivelant of an sql view

Posted on 2011-03-19
2
259 Views
Last Modified: 2012-05-11
Hi,

In sql you can create views such as:

CREATE VIEW vwAveragePrice AS
SELECT Manufacturer, ManufacturerWebsite, ManufacturerEmail, AVG(Price) AS AvgPrice
FROM Manufacturer

SELECT * FROM vwAveragePrice

How can i do this in linq?

basically i have a search result query which returns a list of results, and i want to query this to count distinct records and count them using this:

var results = from tbl in dbEmp.tbl_datas
                      where tbl.searchresultstable.Trim().Length > 0
                      group tbl by tbl.searchresultstable into g
                      select new { var_text = g.Key, var_count = g.Count() };

how can this be done?

thanks,

Sam
0
Comment
Question by:OTM
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35172244
Instead of querying "dbEmp.tbl_datas" substitute in your search result query object. You'll need to modify the "where", "goup by", and select accordingly.
var results = from row in searchResultQuery
                      where row.Member == someCondition
                      group row by row.SomeMember into g
                      select new { var_text = g.Key, var_count = g.Count() };

Open in new window

0
 

Author Closing Comment

by:OTM
ID: 35197034
Thanks, querying the query itself instead of a table gave me the result i was looking for.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question