添加toList时,查询列表返回Null

时间:2018-05-31 10:44:59

标签: c# asp.net-mvc

我试图提供我正在处理的问题的简化版本。查询1被枚举并返回namespace Calculator { public partial class Form1 : Form { Double value = 0; String operation = ""; bool operation_pressed = false; public Form1() { InitializeComponent(); } // Handler for buttons private void button_Click(object sender, EventArgs e) { // I made this because it's simpler, than making 10 methods for each number // When you click on button // The label will check which button did you press if ((result.Text == "0") || (operation_pressed)) // Clearing the zero on the beginning or when we used one operation result.Clear(); operation_pressed = false; Button b = (Button)sender; // Capturing which button was pressed if (b.Text == ".") { if (!result.Text.Contains(".")) { result.Text = result.Text + b.Text; } } else result.Text = result.Text + b.Text; } private void button18_Click(object sender, EventArgs e) { result.Text = "0"; // CE button reset the result back to 0 } // Handler for operators private void operator_click(object sender, EventArgs e) { Button b = (Button)sender; // Capturing which button was pressed if (value != 0) { if (b.Text == "√") //result.Text = Math.Sqrt(Double.Parse(result.Text)).ToString(); result.Text = Operators.sqrt(Double.Parse(result.Text)).ToString(); else { equal.PerformClick(); // Instead of pressing equals button everytime when we press our second + button it will be calculated operation_pressed = true; operation = b.Text; equation.Text = value + " " + operation; // To see what you have typed in before } } else if (b.Text == "√") // Checking if the square root button was pressed { //result.Text = Math.Sqrt(Double.Parse(result.Text)).ToString(); result.Text = Operators.sqrt(Double.Parse(result.Text)).ToString(); value = Math.Sqrt(Double.Parse(result.Text)); } else { operation = b.Text; value = Double.Parse(result.Text); operation_pressed = true; // When we use the operator to reset the first number , //so we can use new number equation.Text = value + " " + operation; // To see what you have typed in before } } private void button16_Click(object sender, EventArgs e) { equation.Text = ""; // When we press the button equals, we only get the result. switch (operation) { case "+": //result.Text = (value + Double.Parse(result.Text)).ToString(); result.Text = Operators.Add(value, Double.Parse(result.Text)).ToString(); break; case "-": result.Text = Operators.Sub(value, Double.Parse(result.Text)).ToString(); break; case "*": result.Text = Operators.Mult(value, Double.Parse(result.Text)).ToString(); break; case "/": result.Text = Operators.Div(value, Double.Parse(result.Text)).ToString(); break; default: break; } // end switch value = Int32.Parse(result.Text); // Converting string to double operation = ""; // Resetting the operators to empty string } private void button17_Click(object sender, EventArgs e) { result.Text = "0"; // When you click the button C the result will be set to 0 value = 0; // Everything stored in value will be reset. equation.Text = ""; // Resetting the equation we did before } // Method from capturing numbers from your notebook/pc so you don't have to select them evertyime // You can type them with your keyboard private void Form1_KeyPress(object sender, KeyPressEventArgs e) { // MessageBox.Show(e.KeyChar.ToString()); // When we press the button it shows use the value of the button switch (e.KeyChar.ToString()) { case "0": zero.PerformClick(); break; case "1": one.PerformClick(); break; case "2": two.PerformClick(); break; case "3": three.PerformClick(); break; case "4": four.PerformClick(); break; case "5": five.PerformClick(); break; case "6": six.PerformClick(); break; case "7": seven.PerformClick(); break; case "8": eight.PerformClick(); break; case "9": nine.PerformClick(); break; default: break; } } } } List

但是,当我更改查询并在select语句之前添加PersonViewModel时,查询将返回值.ToList()

原因是因为我想首先枚举它,所以我可以处理内存中的值 - 以便使用无法转换为SQL的null等函数。

按预期退货

.toString

返回var query = (from s in context.PersonDetails.GetQueryable(x => x.Id == Id) select new PersonViewModel { Name = s.Person.Firstname, Number = s.Person.Number }).ToList();

null

0 个答案:

没有答案