什么是实体框架上下文复杂类型 [英] What are Complex Types in Context with Entity Framework

查看:181
本文介绍了什么是实体框架上下文复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我学习了很多关于从Pluralsight影片实体框架,所以请原谅我的问题可能看起来newbish但我不明白什么复杂类型是为什么我需要他们。



我知道我必须通过注解或类似这样的流畅API的东西把它们映射:

  modelBuilder.ComplexType< blubb>(); 



也许有人会阐述复杂类型的不用我?


< DIV CLASS =h2_lin>解决方案

假设你有一个课程在一类的实体,该实体地点,日期及时间的简单属性,但你找到你想要的抽象的,这样其他实体可以使用相同的模型。所以,你可以创建一个复杂类型,包含天,地点和时间给它一个名字:ComplexType1。现在,其他实体可以仅仅通过在模型定义声明ComplexType1使用这种类型,而不是单个标量的属性。


Right now I am learning a lot about the Entity Framework from Videos on Pluralsight, so excuse my Question which might look newbish but I can not understand what Complex Types are or why I would need them.

I do know that I have to map them via Annotations or Fluent Api something like this:

modelBuilder.ComplexType<blubb>();

Maybe someone could elaborate the need of Complex Types for me?

解决方案

Assume you have an entity for Courses in a class, that entity has scalar properties of Location, Days and Time, but you find you want to abstract that so that other entities can use the same model. So you can create a complex type that contains Days, Location and Time give it a name: ComplexType1. Now other entities can use this type rather than individual scalar properties just by declaring ComplexType1 in the model definition.

这篇关于什么是实体框架上下文复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆