Solved

linq equivelant of an sql view

Posted on 2011-03-19
2
258 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now