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

x
?
Solved

mvc, linq, join and group and grid problem..

Posted on 2010-09-22
4
Medium Priority
?
830 Views
Last Modified: 2012-05-10
Hello,

In my company we are working on a new CMS and one of the feature that we add to the system is the option to create a custom forms with different inputs like text, select box etc.

We manage to finish this part and now we are building the result part which needs to show the result that sent through the custom form.

We have a "FormsOrders" table which stored the answer that sent through the custom form in this way:
**OrderID**  - just an id saved as GUID

**NumOrder** – the address's id (every time someone fill the form I increase it by one) save as int

**ControlID** – GUID of the control. Each control (like textbox, select box etc.) Have is own ControlID and it's stored in "FormsControls" table.

**Value** – the value of the specific control id the address.

For example:
I Have contact form with 3 textbox field (first name, last name, message).
The "FormsControls" table will look like this:

formscontrols1.png

After someone submits an address, the "FormsOrders" table will look like this:

formsorders1.png


And another address will look like this:

formsorders2.png

And so on…

Now, I am trying to join the "FormsControls" value and "FormsOrders" value and get something like this:

goodresult.png


I can join them with linq using the same ControlID but than my table look like this:
trytojoin.png

But it's not helping me because I am using this example
http://weblogs.asp.net/rajbk/archive/2010/05/08/asp-net-mvc-paging-sorting-filtering-using-the-mvccontrib-grid-and-pager.aspx
(Which using the MvcContib Grid and Pager).

Now, all I want is to get the "FormsControls" Values as a column and the FormsOrders as a Value and group all the same numorder  in one row.

Like this:

goodresult.png

Me and another dev working on this for 2 days and we can't figure out how to fix this.

We tried join by NumOrder (which only give us the key and value column – not good for us),
We tried to make new datatable with the columns and rows (we manage to make the datratable but the MvcContib grid is not working with datatable).

We tried dynamiclinq (we didn't succeed with that).

And so on…

I just want to get all the address, to show each address in one row and to be able to sort them and search in those rows.

I will glad to get any idea how to do that…

Please help me.
0
Comment
Question by:ateam
[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
  • 2
4 Comments
 
LVL 7

Expert Comment

by:gsiric
ID: 33733795
Hi,

Create 3 pseudo tables: one contains firstname, second lastname, third message.
Then join them on NumOrder to  get desired result.
This sql assume that you allways have all 3 values (for all controls) in the FormsOrders table.

This is an example:

SELECT  FirstName,LastName,Message FROM
( SELECT NumOrder, Controld, Value As FirstName from FormsOrders Where ControlID='controlid of fisrtname' ) As FormsOrdersFirstName,
( SELECT NumOrder, Controld, Value As LastName from FormsOrders Where ControlID='control id of lastname') As FormsOrdersLastName,
( SELECT NumOrder, Controld, Value As Message from FormsOrders Where ControlID='control id of message') As FormsOrdersMessage
WHERE FormsOrdersFirstName.NumOrder = FormsOrdersLastName.Order AND FormsOrdersFirstName.NumOrder = FormsOrdersMessage
0
 

Author Comment

by:ateam
ID: 33734370
Thanks for the answer, but the is that i dont know what is the column becuase the end user is the that create the form and it can with more than just first last name and message. I can only get the column name dynamicly from the formcontrol table
0
 
LVL 7

Assisted Solution

by:gsiric
gsiric earned 1000 total points
ID: 33734914
Does grid accept dinamicaly created SQL ?

You can dinamicaly create sql like in this pseudo code :)

stringarray columns;
stringarray tables;
stringarray joins;

for int (i=0;i<controls.getsize();i++)
{

  Control control = controls[i];
  columns.add (control.Name.ToText());    
 
  tables.add("SELECT NumOrder, Value As " + control.Name + " FROM FormsOrders Where ControlID=" +  
 control.ID + ") As FormsOrders + control.Name;

  // join
  if (i>0)
  {
        joins.add(" FormsOrders" + controls[0].Name + " = FormsOrders"+control.Name] );
  }
 
}

//create sql

sql = "SELECT " + MakeCommaDelimitedString(columns)  
     +  " FROM " +  MakeCommaDelimitedString(tablles)
     + "WHERE " + MakeJoinString(joins) ;

 
0
 

Accepted Solution

by:
ateam earned 0 total points
ID: 33778298
Hey gsiric,

Thank you for your help.

The dinamicaly create sql doesnt work well with the mvccontrib.

I found another way to do this with dynamic property, but it was very slow.
in the end i change the table and stop to work  multipurpose table.


Lior
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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