Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

linq equivelant of an sql view

Posted on 2011-03-19
2
Medium Priority
?
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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