LINQ: List with max values [closed] - asp.net-mvc

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
i have this query in SQL Server
select max(win_votos), win.cdt_id, cdt_nome
from tb_ganhadores_win as win
inner join tb_candidatos_cdt as cdt on cdt.cdt_id = win.cdt_id
group by win.cdt_id,cdt_nome
<--
and i need to create a list 'AspNetMvc' page, like
public ActionResult ListWinners(int? id){
LINQ QUERY HERE
return View('that list');
}
sorry about my english
can anyone help me please?

var res= (from win in dbContext.tb_ganhadores_wins
join cdt in dbContext.tb_candidatos_cdts
on win.cdt_id equals cdt.cdt_id
select new {win,cdt})
.GroupBy(x=>new{Id=x.win.cdt_id,Nome=x.cdt.cdt_nome})
.Select(x=>new
{
Votos=x.Max(z=>z.win.win_votos),
Id=x.Key.Id,
Nome=x.Key.Nome
})
.ToList();

If you use entity framework and your model name is like this you can use some think like this:
var result = from win in tb_ganhadores_win
join cdt in tb_candidatos_cdt on cdt.cdt_id = win.cdt_id
group win by new { win.cdt_id, cdt_nome } into g
select new
{
max = g.Max(win_votos),
win.cdt_id,
cdt_nome
};
and return result.ToList();
note :
"tb_ganhadores_win"
and
"tb_candidatos_cdt"
is your models.Replace it by what you want

Related

How to upload file from phone and send it as FormData Ionic 4 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm using Ionic trying to use chooser plugin to chose file from phone, transform the URI to a File and send it as FormData. Nothing seems to work.
You can initialize FormData object by creating an instance from new FormData interface as given below.
const formData = new FormData()
const formData = new FormData();
formData.append('firstname', this.firstname);
formData.append('lastname', this.lastname);
formData.append('email' , this.email);
formData.append('phone' , this.phone);
formData.append('experience' , this.experience);
formData.append('userId' , this.userInfo.user.id);

https://youtu.be/7r7UUulUdag [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to convert id into string to use in url
#tutorial_id = Demotutorial.where("job_id = ?", #job_id).select( "id")
#t_id = #tutorial_id.to_s
render json: #t_id
Getting this error
S
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Tutorial Json array
{"demotutorials":[{"demotutorials":{"id":50}}]}
there are two things for your problem
if you using where the result is activerecord relation, which can
have couple of records, you must select which row, I gave you
sample first fow to choose first record
#tuturial_id is a activerecord row, so you must choose which column, I gave you sample using #tutorial_id.id
below is sample code:
#tutorial_id = Demotutorial.where("job_id = ?", #job_id).select( "id").first
#t_id = #tutorial_id.id.to_s
render json: #t_id
Following code is work for me
#tutorial_id = Demotutorial.where("job_id = ?", #job_id).select( "id").first
#t_id = #tutorial_id[0].id.to_s
render json: #t_id

Dart Flutter : How to use multiple statements in ternary inside a flutter widget [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to write such a line, and within this line I want change a variable value?
opacity: condition == true ? 1, stringName ='Steve' : 0
Not sure what you expect the code to do exactly but my guess
opacity: condition == true ? (){ stringName = 'Steve'; return 0; }() : 0;
You can't have a list of expressions in the true or false part, only one single expression.
I think this is what you wanted
opacity : condition== true ? 1 : stringName == "Steve" ? 0 : 2,
I am not sure you will be able to achieve the best result in a case like this using ternary expressions. Instead, you can create a sperate function that you can bundle in all your conditions and maybe return an appropriate variable as the case may be.
After the you can call the SetState() Function to update your widget.

Asp.Net MVC Program error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Why below error is coming in code ? What I do?
public ActionResult Edit(int? id)
{
Emp emp = from c in db.Emps.Where(e => e.EmpId == id).Select(c).SingleOrDefault();
EmpModel model = new EmpModel()
{
EmpId = emp.EmpId,
EmpName=emp.EmpName,
EmpJob=emp.EmpJob,
EmpSalary=emp.EmpSalary,
DeptId=emp.DeptId
};
return View(emp);
}
Errors:
1)The name 'c' does not exist in the current context Error:
2) A query body must end with a select clause or a group clause
Click here to see Image
Because you have used the select extended method which requires you to select needed fields that you want in your Emp object. By the way you Don't really need to use From a in db when you are using LINQ Query Syntax
for example:
Emp EmpObj = Db.Emps.Where(e => e.EmpId == id).Select(x => x.EmpName).SingleOrDefault();
This select query will return only one specific value. But if you need multiple parameters out from it. You can return an object from Select extended Method like this:
.Select(x => new {x.Name, x.Address, x.Gender} ).SingleOrDefault();
Hope that helps and Please, before you question again do read; How should i ask a good question?
You don't need the from c in part for this syntax, and you can simplify the rest quite a bit as well:
Emp emp = db.Emps.SingleOrDefault(e => e.EmpId == id);
Try below code
EmpModel model = db.Emps.Where(e => e.EmpId == id).Select(x => new EmpModel { EmpId=x.EmpId , EmpName =x.EmpName, EmpJob =x.EmpJob, EmpSalary=x.EmpSalary, DeptId=x.DeptId }).SingleOrDefault();

Json and Ruby creating a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a method that I can to push to a JSON call. The function looks like:
def my_function(name, text , id_person, id_company)
end
What I want is to get:
{"my_function":{"name":"names_value","text":"text_value ","id_person":"id_person_value","id_company":"id_company_value"}
Is there any easy way to do this?
The question is a bit unclear, but let me try with few answer possibilities
First of all this is not a JSON format
{"my_function":{"name":"names_value","text":"text_value ","id_person":"id_person_value","id_company":"id_company_value"}
There should not be double quote (") before semicolon (:)
obj = {
my_function:
{
name: "names_value",
text: "text_value",
id_person: "id_person_value",
id_company: "id_company_value"
}
}
If you want to get each of the data in that "JSON" format, you could do this
name = obj['my_function']['name'] #name_value
text = obj['my_function']['text'] #text_value
and so on...
But if you want to make a string data into JSON format, you could do this
def my_function(name_value, text_value, id_person_value, id_company_value)
{
my_function:
{
name: name_value,
text: text_value,
id_person: id_person_value,
id_company: id_company_value
}
}.to_json
end
I hope it's answering your question...

Resources