How to get values in dropdown list from database in icefaces? - icefaces

i just wanna list the list of employee names from database in the dropdown list using ice faces . can anyone suggest me how to write the query in icefaces page to get the list of employees in the database . say table name is "employee" .
Thanks in advance .

I do it like this.
in your bean call your business class
e.g:
ArrayList<SelectItem> selectEmployees = new ArrayList<SelectItem>();
ArrayList<Employee> employees = company.getEmployees(); //this one calls the EmployeeDAO to get the records from database.
for(int i = 0; i < employees.size(); i++){
selectEmployees.add(new SelectItem(employes.get(i).getId(),employees.get(i).getName));
}
now you can use selectEmployees as the value of the selectOneMenu.

Related

Not able to use IN query in LINQ with Entity Framework

I am using EF Framework to retrieve the data from SQL DB.
Sub Request Table looks like below:
In this table "org_assigneddept" is foreign key to another Department Table.
I have list of Departments as Input and I want to retrieve only those rows from DB whose org_assigneddept is matching the list.
Please find my whole code:-
private List<EventRequestDetailsViewModel> GetSummaryAssignedDeptEventRequests(List<EmpRoleDeptViewModel> vmDept)
{
List<EventRequestDetailsViewModel> vmEventRequestDeptSummary = new List<EventRequestDetailsViewModel>();
RequestBLL getRequestBLL = new RequestBLL();
Guid subRequestStatusId = getRequestBLL.GetRequestStatusId("Open");
using (var ctxGetEventRequestSumm = new STREAM_EMPLOYEEDBEntities())
{
vmEventRequestDeptSummary = (from ers in ctxGetEventRequestSumm.SubRequests
where vmDept.Any(dep=>dep.DeptId == ers.org_assigneddept)
select new EventRequestDetailsViewModel
{
SubRequestId = ers.org_subreqid
}).ToList();
}
}
It is giving the following error at the LINQ Query level:-
System.NotSupportedException: 'Unable to create a constant value of
type 'Application.Business.DLL.EmpRoleDeptViewModel'. Only primitive
types or enumeration types are supported in this context.'
Please let me know as how can I achieve the result
You cannot pass the department VMs to SQL, it doesn't know what those are.
// Extract the IDs from the view models.. Now a list of primitive types..
var departmentIds = vmDept.Select(x => x.DeptId).ToList();
then in your select statement...
..
where departmentIds.Contains(id=> id == ers.org_assigneddept)
..

Laravel Eloquent Relationship 3 tables

I am a newbie to Laravel 5.2 and am working on a legacy system and am a bit confused regarding eloquent and would appreciate someone giving me the code.
There are 3 tables:
cards
categories
cards2cat
cards can be part many categories which are kept in cards2cat table.
The cards2cat table has the following structure
id (primary key)
image (card)
category
What I want to do is to have a method in the Cards model called something like getCardsWithCategores which returned the cards info plus the names of the categories from the category table.
The categories table has a key of id and a field category.
Thanks!
Go to your Card2Cats model and add this:
public function categories()
{
return $this->hasOne('App\Categories','id','category');
}
public function cards()
{
return $this->hasOne('App\Cards','id','image');
}
For the query you do this:
$cards = Card2Cat::with('categories','cards')->get();
foreach ($cards as $key => $value) {
echo $value->id.', Card:'.$value->cards->name.', Category:'.$value->categories->category.'<br>';
//$value->cards gives you all column of cards and you can do
//$value->cards->colName
// same goes for $value->categories
}
Make sure the spelling of your classes and table column names are correct before running the code :D

how to show list of CustomerId in dropdown list

i want to create Customer diary on the base of customerID that present in customer table.
In customerID field i want dropdown list having list of CustomerId's that are present in database
How can i do that ? can someone help me please
var _objAllCustomerIds = null;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
_objAllCustomerIds = context.MyCustomers.Select(customer => customer.Id).ToList();
}
//where AdventureWorksEntities is your DBcontent containing all your entities
//MyCustomers is the entities representation of your customer table
if this is in your .aspx file
then in your .aspx.cs file (assuming you're using code behind) you'd get the list of customer IDs and then bind that list to this dropdown.
Does this answer from another question help?
How to bind the selected value of a DropDownList

How to Convert list into other list using entityframework

I have two model classes first one is "Ticket" and other is "ExpTicket" there is only one additional column/properties in ExpTicket and others properties are same in both lists. I extract the data from database in the form of ExpTicket list and then re-assign all column/properties to Ticket List except one additional column which does not exist in Ticket list.
But iam unable to assign data from "ExpTicket" list to "Ticket" list. If anyone can timely help I shall be very thankful. Following is the code which i need to convert From ExpTicket into "Ticket" List but failed. Please help.
var GetTicket = ticketRepository.ExpTicket(r => r.TicketId == TicketId).ToList();
List<Ticket> CTicket = GetTicket.ToList();
First you have:
var GetTicket = ticketRepository.ExpTicket(r => r.TicketId == TicketId).ToList();
Then make a query:
var CTickets = (from t in GetTicket
select new Ticket{field1=t.field1,field2=t.field2...}).ToList();
Or just readjust your model to use TPT (Table per type, Table per type code first) Good luck
var CTickets = new List<Ticket>();
var ExpTicket = ticketRepository.Where(r => r.TicketId == TicketId);
foreach (var ticket in ExpTicket)
{
CTickets.Add(new Ticket { TicketId = ticket.TicketId, ... and so on });
}
// CTickets is the new list of tickets

How to fetch a list inside a list using LINQ to Entities

I have a requirement where i need to display a list in jquery DATATABLE. one of the column in a row will have multiple items (list).
So, in Busines Logic while fetching the DB details i'm trying to fetch a list which has another list in a row.
listTest =
(from TestA in context.Business
join Status in context.BStatus
on TestA. BStatus_Id equals Status.ID
join Prior in context.Priority
on TestA.Prior_ID equals Prior.ID into PriorityDetails
from PrtryDT in PriorityDetails.DefaultIfEmpty()
select new PModel
{
Id = TestA.ID,
Name = TestA.NM,
PriorityEvaluatedOnTS = TestA.PRI_EVAL_ON_TS,
//RequestPriority = i need to write a linq here to fetch a list for RequestPriority
}).ToList();