空的值的复杂类型

编程入门 行业动态 更新时间:2024-10-11 19:23:34
本文介绍了空的值的复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于只可空性实体框架的复杂类型,这是为什么这样的事情如下要求复杂类型被实例化:

For a complex type in entity framework with only nullable properties, why is that for something like the following requires the complex type be instantiated:

[ComplexType] public class Address { public string Address1 { get; set; } } public class Customer { [Key] public int CustomerId {get;set;} public Address Address {get;set;} }

更具体地说,如果你不声明和地址类型,你会得到一个不可为空的会员会籍空值:'地址'。按照这个问题。

More specifically, if you don't declare and address type, you get a "Null value for non-nullable member. Member: 'Address'." As per this question.

只要在复杂类型的所有属性都是空的,那为什么实体框架需要地址的实例?由于地址1是空的,为何不能只是假设,并创建表中的行(和列Address_Address1)和空值,如果我创造了地址的实例,一个空地址1?

As long as all the properties in the complex type are nullable, why is it that entity framework requires an instance of Address? Since Address1 is nullable, why can it not just assume that and create the table (and column Address_Address1) and null value in the row as if I had created an instance of Address with a null Address1?

还是有我可以申请获得一个属性/流利的设置?

Or is there an attribute/fluent setting I can apply to achieve that?

推荐答案

即使属性是空的,包含它们的类不是。你可以有 Address.Address1 为空,但地址本身有被实例化。

Even if the properties are nullable, the class containing them isn't. You can have Address.Address1 as null, but Address itself has to be instantiated.

更多推荐

空的值的复杂类型

本文发布于:2023-11-16 15:26:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!