Solved

linq equivelant of an sql view

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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