如何在Entity Framework中将复杂类型序列化为xml?

时间:2022-10-22 11:19:50

I have two classes called customer and address,customer is an entity while address is a value object.The definition of the classes are below:

我有两个叫做客户和地址的类,客户是一个实体,而地址是一个价值对象。这些类的定义如下:

 public class Customer
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Address ShippingAddress { get; set; }
    public Address BillingAddress { get; set; }
}
 [ComplexType]
public class Address
{
    public string City { get; set; }
    public string Street { get; set; }
    public string StateOrProvince { get; set; }
    public string Country { get; set; }
}

If I create a new customer and insert it into database using entity framework,the customer table has 11 columns,there are 8 columns for address property.How to config the entity framework so that the complex type "address" can be stored as a xml type(single column) in the customer table.

如果我创建一个新客户并使用实体框架将其插入数据库,则customer表有11列,地址属性有8列。如何配置实体框架,以便复杂类型“地址”可以存储为xml在customer表中键入(单列)。

1 个解决方案

#1


0  

you may use https://servicestack.net/text. Although it does not serialize to XML, it's a good JSON serializer.

你可以使用https://servicestack.net/text。虽然它没有序列化为XML,但它是一个很好的JSON序列化程序。

#1


0  

you may use https://servicestack.net/text. Although it does not serialize to XML, it's a good JSON serializer.

你可以使用https://servicestack.net/text。虽然它没有序列化为XML,但它是一个很好的JSON序列化程序。