Types of Entity in Entity Framework
来源:互联网 发布:数据库刘卫国课后答案 编辑:程序博客网 时间:2024/06/05 00:16
在Entity Framwork 5.0/6.0中有两种类型实体:POCO 实体和动态代理实体
POCO(Plain Old CLR Object) 实体:
POCO类是不依赖任何框架中特殊的基类,它与其它普通的.net类类似所以才叫"Plain Old CLR Objects".
这些POCO类支持大部分的查询,插入,修改,删除那些通过Entity Data Model生成的实体操作。
public class Student { public Student() { this.Courses = new List<Course>(); } public int StudentID { get; set; } public string StudentName { get; set; } public Nullable<int> StandardId { get; set; } public Standard Standard { get; set; } public StudentAddress StudentAddress { get; set; } public IList<Course> Courses { get; set; } }
Dynamic Proxy:
Dynamic Proxy是一个POCO 实体在运行时的代理类,它可看作是POCO实体的包装类。
动态代理实体可以Lazy loading和automatic change tracking.
POCO 实体应该符合下面要求才可用作POCO proxy:
1.一个POCO 类必须被声明为public.
2.一个POCO 类必须不能是sealed.
3.一个POCO 类必须不能是abstract.
4.每个导航属性必须声明为public,virtual.
5.每个collection属性必须是ICollect<T>.
6.ProxyCreationEnabled option 必须是true(默认是true)在context类.
以下是Student POCO实体都符合上述的要求在运行时会看成Dynamic proxy entity.
public class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentID { get; set; } public string StudentName { get; set; } public Nullable<int> StandardId { get; set; } public virtual Standard Standard { get; set; } public virtual StudentAddress StudentAddress { get; set; } public virtual ICollection<Course> Courses { get; set; } }
Entity can have two types of properties, Scalar properties and Navigation properties.
Scalar properties:
Scalar properties are properties whose actual values are contained in the entity. For example, Student entity has scalar properties e.g. StudentId, StudentName. These correspond with the Student table columns.
Navigation properties:
Navigation properties are pointers to other related entities. The Student has Standard property as a navigation property that will enable application to navigate from a Student to related Standard entity.
- Types of Entity in Entity Framework
- Batch Updating in Entity Framework
- Entity Framework in Action摘要
- Entity FrameWork
- Entity Framework
- Entity Framework
- Entity FrameWork
- Entity Framework
- Entity Framework
- Entity Framework
- Entity Framework
- entity framework
- Entity Framework
- entity framework
- Entity Framework
- Delete child objects in Entity Framework
- Entity Framework 4 In Action 读书笔记
- ADO.NET Entity Framework: The version of SQL Server in use does not support datatype 'datetime2'
- linux 根据文件大小查找文件
- 指针管理
- 【OC语言基础】之布尔类型的使用
- 黑马程序员———正则表达式
- 对EventLoop和性能问题处理的理解
- Types of Entity in Entity Framework
- Java并发编程:volatile关键字解析
- onClick、onLongClick事件同时触发
- 用c /c++编写mex 程序并编译MATLAB的Mex文件的方法
- Android中BroadCast与Activity之间的通信
- 递归删除文件或目录
- SpringMVC4+spring3+Myibats3
- 软件测试之-软件缺陷管理
- 信心等于成功