Solved

linq equivelant of an sql view

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

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
Thanks, querying the query itself instead of a table gave me the result i was looking for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 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