How to add Count of child table in EntityDataSource - entity-framework

I have an EntityDataSource that works to get row data from tblOrderFile as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles"
Select="it.[pkOrderFileID], it.[fkOrderFileStatusID], it.[Filename], it.[CreateDate], it.[UserId]"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="">
I would now like to modify it to also return back the number of rows in child table tblOrderFileItem (with Entity Set Name tblOrderFileItems).
I found a way to get the Count to work by adding an Include directive as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles" Include="tblOrderFileItems"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="" >
</asp:EntityDataSource>
but I believe this is returning the all the columns of all the rows for each Order Item. I only really want the Count and do not want to deliver the rest of the data to the web page.
I also tried simply adding it.tblOrderFileItems.Count to the Select statement but get an error saying
'Count' is not a member of 'Transient.collection[MyDBModel.tblOrderFileItem(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection.

Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"

Related

Pass values from select option to input field and back

Just asked another question but i think I need a much simpler solution.
Therefore i have made this JSFiddle:
http://jsfiddle.net/4EVBL/18/
<select name="selection" class="box1" style="width: 200px; height: 100px;" multiple>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
Is it possible to have the values (1 and 2) selected in the selected "box" on load, so it is possible to see which ones are selected. And is it possible to have the values of the input field divided by comma, so if one add "3" the value in the input fild will be 1,2,3. Can it also be done so that if you remove the value "2" in the select field the input field will say 1,3 ?
Any tips or help is much appreciated :)
You only need to make a couple of changes to your existing code. To populate the select on load, the following will suffice:
$(".box1").val($(".box2").val().split(","));
which populates .box1 with an array of values.
Meanwhile, to populate the textbox when the select box changes, use the .val() method instead of complicating it with :selected selectors and .text() methods:
$(".box1").change(function () {
$(".box2").val($(this).val());
});
JavaScript will automatically do a .toString() of the array into a comma-separated list of selected values.

Nested Filter options in Spotfire

I am learning to create reports using spotfire. Could you please help me to understand the feasibility.
Is it possible to change the filters based on the previous selection(filters has to be altered based on the previous section)
For Example:
I have a following table, with three columns.
Filter1 Filter2 Data
Name Name1 test1
Age Age1 test2
Location Location1 test3
I am planning to have filter options based on the column Filter1 and Filter2.
Is it possible to create a drop down with the values "Filter1" and "Filter2"?
Is it possible to modify the list of filter options, based on the first drop down selection.
For example. if "Filter1" is selected in the drop down. The list of filter options should be "Name","Age", "Location".
if "Filter2" is selected in the drop down. The list of filter options should be "Name1","Age1", "Location1".
Thank you
We can also create a cascading drop down list through the following steps.
Create a “property Control – Drop down list” myDropDownList
Select the “Unique Column Value ” to populate the drop down list (values).
Go to “Insert -> Calculated Column”
Use a simple conditional statement something like If([Value1] = ‘${myDropDownList}’, [Value 2], NULL)
Use the newly created column in the text area filter. This will be updated based on the previous section.
Thanks.
I have a solution utilizing JavaScript to effectively toggle between hidden DIVs. I'm not aware of a way to manipulate the filter object and which column it points to in the Text Area through the API. If someone does know a way I'd love to hear it!
Here is my solution with JS:
Set up your Text Area with a Drop Down for your selection as a column selector (with columns of interest chosen through the "Select Columns..." dialogue), a label displaying that selection (we will hide this, I realize it seems redundant), and 2 filters for your 2 columns.
Right click your text area and click Edit HMTL. Utilizing the HTML below, modify your HTML to match. You will want to have the 1st DIV as your drop down, the SPAN as your label which displays that drop down's property, and then the last 2 DIVS (LETTER and NUMBER in my case) as your two filters. Make sure the DIV id name matches your column name exactly.
<DIV><SpotfireControl id="8dc9d8974bde445cab4c97d38e7908d6" /></DIV>
<SPAN id=docProp style="DISPLAY: none"><SpotfireControl id="1311015997cd476384527d91cb10eb52" /></SPAN>
<DIV id=LETTER style="DISPLAY: none"><SpotfireControl id="760ae9ffd71a4f079b792fb5f70ac8b4" /></DIV>
<DIV id=NUMBER style="DISPLAY: none"><SpotfireControl id="488ef4b1289440d5be24b0dd8cfc3896" /></DIV>
Next we will implement the JS. To do so, click the +JS button in your Edit HTML. The JS itself is below. You'll want to change my inputs of LETTER and NUMBER in the first 2 getElementById references where we set them to display:none.
filter = function(){
input = $("#docProp").text().trim() //Take the text from our hidden label and trim it from any white space.
document.getElementById("LETTER").style.display = 'none'; //Reset DIV
document.getElementById("NUMBER").style.display = 'none'; //Reset DIV
document.getElementById(input).style.display = 'block'; //Set new display
}
//Run this function every 333ms or other length of time desired to update your filters.
setInterval(filter,333)
//Larger numbers mean slower response and better performance vs. faster response and worse performance. Tune as necessary.
Alternatively instead of scanning every X milliseconds (can cause some performance drag), you can make a JS button to run it manually. e.g. $("#divIdForButtonPlacement").button().bind('click',filter)
A few images of my setup for testing are shown below. Let me know if you have any questions regarding this.

How can I pull data in a controller and form for one model that is in a different model with out a foreign key relationship?

I am new to rails and haven't really done to much with data outside of the model.
I have a form that references a table controller for files. I want to add an dropdown that will display a list of projects from a project table for the user to assign a the file to a project if they want too. Assigning a project is not a requirement. The file can be unassigned to a project. I do have a project_id column in the file table for those projects assigned but it is allowed to be null and I did not build a relationship because I need to have cases where there are none.
Can someone please tell me how to do this?
When they evaluate the file, the screen posts back with a save or update button depending if it has already been saved in the database.
At the same time as the save and update pop up on the right I want to display a list box of the projects with an assign project button. If new just a list, if update either just a list because not assigned or display the selected value in the list if already assigned, while allowing them to change it from the list if desired.
In the file controller method that posts back to the UI I have this code:
#file_alias_filedata = FileAliasFiledata.all
#projects = Project.all
for update
#projects = Project.find(params[:id])
In the form I have this code:
<p> <label> Select Project to Assign:</label> <br />
<%= select_tag 'projects', (#projects.present? ? options_for_select(#projects, #selected_project) : []) %> </p>
The form runs but I get this in the dropdown box:
#<Project:0x))7ff531ab4518>
Can someone please help me figure out how to accomplish my task and why I see the strange box value?
What am I doing wrong?
Thank you for your help!
Assigning a project is not a requirement. The file can be unassigned
to a project. I do have a project_id column in the file table for
those projects assigned but it is allowed to be null
From the docs:
belongs_to(name, scope = nil, options = {}) public
Specifies a
one-to-one association with another class. This method should only be
used if this class contains the foreign key. If the other class
contains the foreign key, then you should use has_one instead. See
also ActiveRecord::Associations::ClassMethods’s overview on when to
use has_one and when to use belongs_to.
Methods will be added for retrieval and query for a single associated
object, for which this object holds an id:
association(force_reload = false)
Returns the associated object. nil is returned if none is found.
Likewise,
has_many(name, scope = nil, options = {}, &extension) public
Specifies
a one-to-many association. The following methods for retrieval and
query of collections of associated objects will be added:
collection(force_reload = false) Returns an array of all the
associated objects. An empty array is returned if none are found.
But belongs_to() and has_many() are supposed to make things more convenient for you. You certainly do not have to use them.
Next,
and why I see the strange box value? What am I doing wrong?
You see the strange value for the same reason the following two loops display different things:
class Dog
attr_reader :name
def initialize(name)
#name = name
end
end
#dogs = [
Dog.new("Sam"),
Dog.new("Betty"),
Dog.new("Pete"),
]
#dogs.each {|dog| puts dog}
#dog_names = #dogs.map {|dog| dog.name }
#dog_names.each {|dog_name| puts dog_name}
--output:--
#<Dog:0x0000010099a308>
#<Dog:0x0000010099a2b8>
#<Dog:0x0000010099a268>
Sam
Betty
Pete
You will see the same result if you do something like the following in a view:
<div>
<%= select_tag "dog", options_for_select(#dogs) %>
</div>
<div>
<%= select_tag "dog_name", options_for_select(#dog_names) %>
</div>
If you read the docs here:
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
...you will see several examples, which should make it clear that options_for_select() takes an argument that is:
An array of Strings.
A Hash where both the keys and values are Strings.
An enumerable that iterates over some Strings.
etc.
Do you see a pattern? It's Strings! options_for_select() needs an argument that consists of Strings. If the argument is not a collection of Strings, e.g. an array of project objects, then options_for_select() tries to convert the objects to strings by calling to_s() on the objects. And the default to_s() method is Object#to_s() which is inherited by all objects and produces a string containing the class name and the object_id.
I am also new to rails, but I think you can try using the options_from_collection_for_select method.
<%= select_tag :search_state, options_from_collection_for_select(State.find(:all, :select => :name), :name, :name) %>
Hope this help. Cause it certainly helped me.

how to retrieve multiple properties of selected list object from struts2 select tag through list key?

I have a list of objects in struts2 select tag. i want to retrieve the selected list object, not just id or any property as none of them or unique property, is there any way to get whole object? my code goes as below i want to retrieve all the fields, name,id,date,cba, seq.. as none of them are unique fields, i can not just get the id, then get the other fields from database.
any help???
<s:select name="appls" list="applList" id="appls"
listKey="id"
listValue="%{enroller.name.fullName + '-' + enroller.cba+'......' + openDateStr + '.....' + seq}"
multiple="true" />
What do you mean, "get the whole object" or "retrieve the list object"?
In any case, IMO you should build complicated option labels in Java, not in the view.
listValue can be an arbitrary OGNL expression, using the same value stack as the page itself, plus each of the select's list items pushed onto the top. Without knowing more about what you're actually trying to do, it's difficult to help much beyond that.

How do I determine the length of a list in RedDot/OpenText?

I have a page with a list element attached. How do I determine the number of items in that list? Can use render tags, asp, or any other technique (so long as it works!)
Reading the render tags documentation I believe it may be possible to do this in a nicer way
So getting the list Element using this
Context:CurrentPage.Elements.GetElement(lst_myPages).Value
The Value property should return a page collection for list items so you should be able to do
Context:CurrentPage.Elements.GetElement(lst_myPages).Value.Count
<!IoRangePreExecute>
<% lst_myPagesSize = 0 %>
<!IoRangeList>
<% lst_myPagesSize = lst_myPagesSize + 1%>
<!IoRangeRedDotMode><!--[if !IE]><%lst_myPages%><![endif]--><!/IoRangeRedDotMode>
<!/IoRangeList>
<!/IoRangePreExecute>
I think this is the fastest way.
First counter = 0. Then in the list range increment the counter (keep in mind to include the list place-holder too in that block). After that you have the value in the counter.
Apparently, the only way to do this is to loop through the list, counting each item, e.g.
<reddot:cms>
<foreach itemname="testList"
object="Context:CurrentPage.Elements.GetElement(lst_myPages).Value"
countername="listCounter">
</foreach>
</reddot:cms>
The length is then available as:
<%!! Store:listCounter !!%>
In OpenText use this render tag to get the length of a list (name of list element: lst_Navigation):
<%!! Context:CurrentPage.GetElementByName(lst_Navigation).GetLinkedContents().Count !!%>
Context/RDObj: by ObjectLoader Context (alias: RDObj) you get access to objects of Management Server
CurrentPage: returns Page objekt from current page
GetElementByName: method from page object to get a page element by name
GetLinkedContents: returns a LinkList object
Count: returns the number of LinkList elements