[英]Does ef6 ignore null values in columns?
Has the rule booked changed in EF6 just when I didnt have a value I was referencing in the line address.当我没有在行地址中引用的值时,EF6 中预订的规则是否发生了变化。
player _player = new player();
_player =_dal.GetPlayerBYID(new Guid("FBC6D7C8-3460-49A0-B78C-03A8FFE24AFC"));
txtFirstName.Text = _player.fname.ToString();
txtLastName.Text = _player.lname.ToString();
txtAddress.Text = _player.address.ToString();
This call to _dal.GetPlayerBYID(new Guid("FBC6D7C8-3460-49A0-B78C-03A8FFE24AFC"));此调用 _dal.GetPlayerBYID(new Guid("FBC6D7C8-3460-49A0-B78C-03A8FFE24AFC"));
may return null.可能返回空值。
When the return value is null and you assign it to _player variable, you now have _player = null;当返回值为空并将其分配给 _player 变量时,您现在拥有 _player = null;
Then when you call fname or lname or address on _player which is null.然后,当您在 _player 上调用 fname 或 lname 或 address 时,它为空。 It will throw an exception.它会抛出异常。 Before calling _player.fname, check it is not null.在调用 _player.fname 之前,检查它是否为空。
ie IE
if(_player != null)
{
txtFirstName.Text = _player.fname.ToString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.