Linq to SQL - Returning a count from two tables - asp.net-mvc

Let me just start off by saying I am very much a beginner and being self taught a lot of the stuff I do is through trial and error, so please forgive me if I seem vague or if I don't explain myself clearly.
I'm currently building an auction website with MVC. I have two tables, one for the auctions and one for bids. There is a foreign key relationship between the column AuctionID on both tables. I need to return a list of the top 5 auctions based on the amount of bids each item has received. At the moment I just want to list the auction title and the amount of bids it has received, something like this > 'A Lovely Item - 25 bids' etc etc.
I have had a go at a few things but to be honest I'm not really sure of the correct way to go about this. I'm using Linq to SQL and MVC. Any help is greatly appreciated, thanks.

If you defined the keys properly and have Bids set up as a Navigation Property of Auctions, then you should be able to use a simple combination of OrderyBy and Take:
var topFiveByBids = db.Auctions.OrderBy(a => a.Bids.Count()).Take(5);

Since you are a self-taught style, check the sample application provided by Microsoft for LINQ for more info
Located here: C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033\CSharpSamples.zip
change drive C with VS 2008 installed drive

Related

How to find when "Function" (date) is added to responsibility Oracle EBS 12.1.3

I was adding new Menu functions to Responsibility and then i updated wrong one. But not sure if it is updated now or it was there before.
So, I am searching for a query to find when a certain menu function is added to the certain responsibility.
Please help me.
If you have SQL query access, the who columns (audit columns) are a good place to start looking - check out the LAST_UPDATE_DATE for the date the modification was made and LAST_UPDATED_BY will tell you who updated the table. All the tables should have them. The tables involved are:
fnd_menu
fnd_menu_entry
fnd_nodes
fnd_user_resp_groups
fnd_resp_function
fnd_responsibility

Meteor publish-with-relations VS collection-helpers for joins?

What's the best way to do joins in Meteor/mongo? Use one of these packages, or something else:
publish-with-relations
https://github.com/erundook/meteor-publish-with-relations/blob/master/publish_with_relations.coffee
collection-helpers
https://github.com/dburles/meteor-collection-helpers
I'm very familiar with PWR, but collection-helpers is new to me. It looks like the two are complimentary.
PWR solves the somewhat complex problem of publishing documents to the client via a reactive join based on arbitrarily complex relationships. See this question for more details.
collection-helpers appears to be a set of convenience functions added to the client to be used when traversing collection relationships inside of a template (given that the required documents have already been published). For example, if you have books and authors in separate (but related) collections, you can immediately get myBook.author.fullName inside of a template without having to type out the extra find for the author.
currently the top popular solution in atmosphere seems to be publish-composite https://atmospherejs.com/reywood/publish-composite

Ruby on Rails: How to have multiple controllers for one table AND multiple models

I'm new to Ruby and to Rails. I have played a bit with Sinatra but I think that Rails is a more complete framework for my project. However, I am running into trouble with this.
I am working with an fairly substantial existing, and heavily used, mySQL database and I am trying to build an API for this that will report on certain features. The features that are needed are, for the most part, counts of records by certain groupings, then drilling down into details.
For example we have a table - tableA, that contains lots of information relating to documentation. One piece of information we want to report on from that is the number of items in a given language. The language code is stored against each item and based on a get request I would like to return JSON.
Request: /languages/:code/count/:tablename
There are two variables in that most specific URL - the code we are counting and the table we are counting from.
I understand that in routes.rb I can set up a mapping:
get '/languages/:code/count/:table', :controller=>'languages', :action=>'count'
I have a controller - languages_controller.rb with a count method in it. this then matches to a corresponding view file count.html.erb
In all the tutorials I have read and examples I have followed the main point seems that 'languages' would be a table in the database and would therefore be available under the 'magic' Rails approach.
My issue is that it is not a table, rather the results of the call should be a limited subset of the fields in tableA. Such as languagecode and count(id).
The description of the language needs to be looked up 'manually' as it is stored as an internal code that is not in a database anywhere (historic decision/madness).
The questions:
how do I have a model that is only a subset of fields, plus some that are manually populated - languagecode, isocode, description, count
Am I right in thinking that once I have the model defined as such as I could use ActiveRecord to get data from the database and then in the controller add the extra information in?
Can I change table in the model based on the parameter sent in the URL?
Essentially, I am at a loss at the moment on what to do with this. I have the routes defined, the view templates in place and the controller there and ready to go. The database component - getting some data from a pre-existing table seems mysterious to me.
Any help is greatly appreciated, it seems that the framework is currently getting in my way and I know that I can't be the only one trying this sort of thing so if you have any advice please share.
There's really no need for a model here, at all. This isn't what ORMs are for. What you should be doing is just running raw SQL against the database, and iterating over the results. Consider doing something like this: https://stackoverflow.com/a/14840547/229044

Dynamics AX 2009 How to change customer invoice layout/printing?

I'd like to change the default customer invoice print to something else. Add an image to the head, change the layout, change the columns, well everything in fact.
Can someone explain how to start this, or maybe point me to some tutorial or reference about this?
So far all I found was ways to create new reports, but I'd like to change the default invoice print, not create something new.
Default sales invoice report is in AOT>Reports>SalesInvoice. This is not an easy report to modify so it is recomendable to add a new design to it instead of modifying the Standard one. This way you always can revert changes to the standard.
You have more information about AX reporting at:
http://msdn.microsoft.com/en-us/library/bb427701(AX.10).aspx
For Dynamics 2009 some of the basics on report modification are actually in the Microsoft Certification books for DEV I, II, III and IV. There are a couple cook books for AX worth looking into as well. MSDN/PartnerSource is always good.
Another approach is to open the "reports" node in the AOT and locate the "tutorial_" prefixed reports which have been created to demonstrate report modification.
ex:
tutorial_Date
tutorial_Joins
tutorial_HelloWorld
tutorial_Prompt

How to design a system like google base with dynamic attributes? in Ruby on Rails

I am wanting to create an application that can allow users to add products for sale.
I want to make it so that a user can add whatever type of product he/she likes and let them also create stored and searchable attributes for their products - alot like google base does.
Does anyone know of the best way to do this ie model it.
I don't really want a table for each category as this would be possibly 1000s of tables.
What is the best way to do this? has anyone got good / bad experiences of this?
Is there any plugins that does this?
Any help would be great
thanks
rick
It sounds like what you want is a tag system.
If you want something more flexible you might want to look at using a document store instead of a database, for example CouchDB.
If you don't want to keep this in a relational database I'd suggest creating a Model called "Descriptor" that would contain the ID of the item being added, the name of the attribute "Color" and the value "Red".
To help keeps things consistent you could also structure pre-set groups of descriptors (for cars: make, model, color) as well as provide auto-completes for the value entry text fields.

Resources