MVC :: Linq To Sql - Create A Query For Only Get The Data
Mar 8, 2011
i"ve build a small (verry small) test app with a UI and a domain model and i'm able to show all the data from one table but now i wanna create a query so i only get the data i want but i have no idea how to do this. i've created a domain model with a entity class, an abstract and a concrete repository (see code)
[Code]....
namespace winkelketen.domain.Abstract{ public interface IwinkelketenRepository { IQueryable<Winkelketen> Winkelketen { get; } }}
namespace winkelketen.domain.Concrete{ public class SqlWinkelketenRepository : IwinkelketenRepository { private Table<Winkelketen> productsTable; public SqlWinkelketenRepository(string connectionString) { productsTable = (new DataContext(connectionString)).GetTable<Winkelketen>(); } public IQueryable<Winkelketen> Winkelketen { get { return productsTable; } } }}
and then i created a UI with a controller
[Code]....
and a view
[Code]....
could something give me some tips how to do this or how to get started?
Is there a straightforward way to create a dataset after querying a dataview? The query itself returns DataRowView objects, which I cannot get to work with CopyToDataTable().
The query looks like:
Dim dvQueryView As DataViewdvQueryView = (dataview object of large dataset) detailTableQuery = From rowView As DataRowView In dvQueryView _ Order By sSortOrder _ Select rowView _ Skip nQuerySkipRow _ Take nQueryCountRows
I only want a small selection of records from the large dataview and use those to create a smaller dataset. The large dataset stays in place while multiple views are created from it, and then from those views I want to create the smaller datasets.
I have a basic Linq query and what I need to do is query the DB then display the data in HTML.Typically I would bind this to a control but in this instance I need to actually generate the HTML in the code behind page.The Linq query is very basic something like this with Northwind:[Code]....
Instead of binding that to a gridview how can I write out the html... I'm sure I can use stringbuilder or smilar to create the html but I'm not sure how to get he data in the tables... foreach datarow in?
I have a web application that uses LINQ-to-SQL. It has a very strange issue, where a LINQ command retrieves the data that is supposed to be returned by another, totally different query that runs in a different thread. What could be the cause of this?
Specifically, a user accesses the application from his machine, opening a certain page. At the same time, another user accesses a different page from his (different) machine. One of the queries throws an exception, while the other returns the data of the first one, which comes from a very different table!
The case is always reproducible, whenever we stress the application with these two users. I've checked but I don't see any shared variables of any kind. What else could the problem be? What should I be looking for?
I've build a linq query.But i want a random selection so its not always ID : 1,2,3,4,5,6 How can i randomize this var? I like to bind it to a repeater.//TagCloud:
Random rand = new Random(); var tc1 = from i in JumpTide.cms.menu.GetMenuItems(32) select new
I am trying to figure out why this service does not return any data. The service does not error out is just doesn't return any data. When I take the Linq into LinqPad the query returns exactly as I expect. So I am wondering if the problem is getting my return data into a List<string>??
[Code]....
I don't know what else to say to help. When I set a break point on the "return LoanStats" line a quick watch shows an empty results view.
currently i am working on wcf...i am adding data through textborex till here is ok. but when i am retriving it from database into grid..but the grid is getting blank...
i am using this query..--page - svc.cs
public List<AddressBook> BindData() { DataClasses1DataContext dc = new DataClasses1DataContext();[code]....
1        Test1      abc     1000 2        Test2      dcf     1000 3        Test3      edf     1000 1        Test1      dcd     1000 2        Test2      dcf     1000
Now I want a linq query to check for the duplicate name and if present adding its rupees...
E.g.: Result will be
     name        rupees
     Test1        2000      Test2         2000     Test3         1000
I am facing a big problem with simple linq query.. I am using EF 4.0..
I am trying to take all the records from a table using a linq query:
var result = context.tablename.select(x=>x);
This results in less rows than the normal sql query which is select * from tablename;
This table has more than 5 tables as child objects (foreign key relations: one to one and one to many etc)..
This result variable after executing that linq statement returns records with all child object values without doing a include statement.. I don't know is it a default behavior of EF 4.0 . I tried this statement in linqpad also..but there is no use... But interesting thing is if I do a join on the same table with another one table is working same is sql inner join and count is same..but I don't know why is it acting differently with that table only.. Is it doing inner joins with all child tables before returning the all records of that parent table?
So the BlogPostTags table only contains 2 fields, BlogPostID and TagID.
When i run the query above i get 3 results back. Same blogpost 3 times but with 1 tag in each. It should return 1 post with 3 tags. The problem lies in the Tags query above.
'm not sure if this is the right forum, but I couldnt find one for linq related questions.I have the following problem. I have four tables, One with users, one with projects, one with the users and the projects they are in (joinProjectTable) and on table where the users can fill in there worked hours for a certain project. These hours are filled in on a daily base. Now every month there is going to be created a report on the workedHours table so there is visible which user has entered how many hours for a certain project. On this report there is gonna be a billing for the company where for the hours are worked. This is the easy part, the hard part is the following.
companies also want to have a list of users that didn't entered any hours for that particular month for a particular project. So I have to write a linq query that would look in the joinprojecttable to see which users are joined to which projects, and than with that join it should look if that particular combination (user+project) is in anyway entered in the workedhourstable for that particular month. If not this has to be shown in the datagrid, for every user that isnt in the workedhourstable for that month. So it should be a certain NOT query, but I can't seem to figure it out.does anyone have any idea to accomplisch this in Linq2Sql? I'm using VB instead of C#.
I am struggling to create a webservice method using LINQ technology and to populate a dropdown in a form. Here is the Webservice code.
[WebMethod]
public string[] GetAllCountries() { LinqClassesDataContext db = new LinqClassesDataContext(); var q = from c in db.ListContinents()select c; return q.ToList() ; }
And here is the form code behind
protectedvoid Page_Load(object sender, EventArgs e) { WSClass WS = new WSClass();//bool ds = WS.GetAllCountries(); var v = WS.GetAllCountries(); ddlContinent.DataSource = v; ddlContinent.DataBind(); }
I've got a gridview that will allow clients to edit options they've already entered on another page. The gridview has three radio buttons in it each with a value of 1,2,3. The option value in the dataset is 1,2 or 3 respectively. I would like to have the radiobutton with the corresponding value selected in the gridview so they can see what they previously chose and will then be able to edit, if they wish.
I have a web app for our golf club. When I compute handicap index for each golfer, I have to select the most recent scores and then a subset of those scores depending on how many rounds of golf the golfer has played. All the scores are entered into a single SQL Express table called "Rounds". Verbally, this is what I'm trying to do:
1) select the twenty most recent golf scores (sort on date descending, "take(20)") [if less than 20 records, then select all available];
2) for this set of records, select the 10 lowest scores (or smaller number if golfer has less than 20 rounds);
3) compute the average round differential for the subset of records, etc. to calculate handicap index (this step is working ok...)
My current VB code has this LINQ query (which is flawed -- it selects the lowest handicap differential scores of ALL records for the filtered user):
[Code]....
How do I modify this query to accomplish items 1) & 2) above? It seems this should be simple, but my experience with queries is still limited.
I am trying to create statitics for game downloads and am having dificulty with a sub part of my query. the goup by command is not having the disired result and i think i have been looking at it too long to see what i am doing wrong. [Code]....
At the moment it is producing each result in many rows when only 4 rows should appear. its the download column that is doing it. needs to be sub queried or something to display total in relation to month,gameid,userid.
I'm new to ASP.net 3.5 and trying to create a test site so I can figure out how to use it in the real world. I have created a FormView (Formview1) based on a Client table using Linq Data Sources. The page includes a DropDownList to lookup Clients. I have added a list option (<asp:ListOption value="" Text="(Select Client)" and set AppendDataBoundItems=true so my added option is displayed. I decided to try to use Formview with only the Edit and Insert Modes, and I have set the Default Mode = Insert. When you open the page, a blank Client record is displayed.
The Client record contains serveral lookup fields and they have drop down lists for each. When I select a client from the Client DropDownList, is get the following message 'ddlClientType' has a SelectedValue which is invalid because it does not exist in the list of items I had this problem before and decided the best way to handle this (in the interim) was to turn off foreign key constraints for each of the lookup fields (e.g. ClientType) in SQL Server. That worked for 2-3 days. Now the problem has started again.
When I develop in other applications, I would simply create a lookup data source based on a Union Query with the actual data and a blank record. How can you do this using Linq DataSources. Can you get access and modify the queries?
For some unknown reason I suddenly am unable to create an object variable for a Linq Data Class. If I create a new project and try the process again with the same database everything works as advertized.The code I am using is Dim db As New RoggDataContext which gives me an error on the object variable "db": Overload resolution failed because no accessibility 'NEW' accepts this number of arguments.I have looked inside every file in the Web Project like the web config to check the connection string, gobal, and designer.vb looking for any errors whit no JOY. I also tried to create a new form and code behind with a button and received the same error.This is mind blowing because as I already stated, I can create a new Web Site and the problem goes away.
my query is SELECT a.HD, a.HEAD, a.SH, a.SUBHEAD, a.TRK, a.TRACK, a.TGT, a.TARGET, a.PDC, a.DT_RELEASE, a.STATUS, a.CO FROM V_HIERARCHY1 a
my data is ,HR HR Rec Records Leave Leave Records HRL.0001 Policy and Process for leave record. 27.06.2010 30.06.2010 WIP Edlink HR HR Rec Records Leave Leave Records HRL.0002 Quarterly Review 01.07.2010 04.07.2010 Planned Edlink HR HR DB Database SAL Salary DDS.0001 Calculation of Monthly salary 08.08.2010 09.08.2010 WIP Edlink HR HR Rec Records Ind Induction Records HRI.0001 Completion of dossiers. 08.07.2010 10.07.2010 WIP Edlink HR HR DB Database Emp Employee HDE.0001 Offer letter 06.07.2010 09.07.2010 WIP Edlink