ef6是否忽略列中的空值?

时间:2015-11-03 23:40:55

标签: c# entity-framework

如果我没有在行地址中引用的值,那么预订的规则是否已在EF6中更改。

$servername = "";
$username = "";
$password = "";
$database = "";

  if($_SERVER["REQUEST_METHOD"] === "POST")
   {
    //form submitted

    //check if other form details are correct

    //verify captcha
    $recaptcha_secret = "xxxxxxxxxxxxxx";
    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
    $response = json_decode($response, true);
    if($response["success"] === true)
    {

        //$conn = new mysqli($servername, $username, $password, $database);
        try{
               $db = new PDO('mysql:host='.$servername.';dbname='.$database,$username,$password);
               $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
        catch(PDOException $e){
              echo "Error connecting to DB";
              echo $e->getMessage();
              exit();
        }

        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        } 

        $email = $_SESSION['userName'];
        $contact = $_POST['naar'];
        $address = $_POST['bericht'];


        $sql_pdo = "INSERT INTO messages (to_user, from_user, message)
                VALUES (:contact, :email, :address)";

        $stmt = $conn->prepare($sql_pdo);

        try {
             $result = $stmt->execute( array(
                ':contact' => $contact,
                ':email' => $email,
                ':address' => $address
                ));
             if ( count($result) > 0 ) {
                // Insert has gone well. Do your things here.
                echo "Logged In Successfully";
             }
             else {
                 // Insert error. Report, check, ...
             }
        }
        catch(PDOException $e){
            echo 'could not insert in DB';
            echo 'Error: ' . $e->getMessage();
            return false;
        }

        $conn->close();
    }
    else
    {
        echo "You are a robot";
    }
}
  • 它在这里崩溃了,如果列中没有值,那么在ef5中没有设置对象,它仍然会被包含在内

1 个答案:

答案 0 :(得分:0)

此调用_dal.GetPlayerBYID(新Guid(" FBC6D7C8-3460-49A0-B78C-03A8FFE24AFC"));
 可能会返回null。

当返回值为null并将其分配给_player变量时,您现在拥有_player = null;

然后在_player上调用fname或lname或地址时为null。它会引发异常。在调用_player.fname之前,请检查它是否为空。

if(_player != null)
{

     txtFirstName.Text = _player.fname.ToString();

}