Note On <Programming Entity Framework 2nd Edition> -04
2015-01-28 15:49
579 查看
Setting Default Values
"You can also set default values in your database, so why define defaults directly in the model? The CustomerTypeID property is non-nullable. Not only is this defined in the database, but it is also defined in the conceptual
model. Because it’s non-nullable in the conceptual model, you must provide a value for this property; otherwise, when you call SaveChanges, a run-time exception will be thrown. Therefore, setting the default in the model ensures that some value is provided
even when the developer doesn’t specifically assign the property value."
Mapping Stored Procedure
The mapping of DeletePayment stored procedure is different from this textbook.
Many-To-Many Relationhips
These tables did not appear in the model as entities. The EDM has the ability to represent many-to-many relationships while hiding the join in the mappings. But it can do this only when the join table has just the relevant keys
and no additional fields. These two tables meet that criterion, as they have only the IDs of the items they are joining. If the join tables had additional properties, such as DateCreated, the EDM would have created entities for them.
Building Assembly
When a project containing an EDMX is compiled, the compiler extracts the StorageModels, ConceptualModels, and Mappings sections of the EDMX file and creates individual schema files from them. In this case, the files are BAModel.ssdl,
BAModel.csdl, and BAModel.msl. By default, these files are embedded into the assembly that is built from the project.
If you look at the metadata portion of the EntityConnection string that the Entity Data Model Wizard inserted into the app.config file, you’ll see the following notation:
Much of the functionality in the Entity Framework depends on its ability to read the schema files. The * in the metadata of the connection string indicates that you can find the files in an assembly. Entity Framework will search
all loaded assemblies until it finds the one with these embedded files.
"You can also set default values in your database, so why define defaults directly in the model? The CustomerTypeID property is non-nullable. Not only is this defined in the database, but it is also defined in the conceptual
model. Because it’s non-nullable in the conceptual model, you must provide a value for this property; otherwise, when you call SaveChanges, a run-time exception will be thrown. Therefore, setting the default in the model ensures that some value is provided
even when the developer doesn’t specifically assign the property value."
Mapping Stored Procedure
The mapping of DeletePayment stored procedure is different from this textbook.
Really? How? |
When a payment is updated, the database will automatically update the RowVersion field. The UpdatePayment procedure returns the new value. |
These tables did not appear in the model as entities. The EDM has the ability to represent many-to-many relationships while hiding the join in the mappings. But it can do this only when the join table has just the relevant keys
and no additional fields. These two tables meet that criterion, as they have only the IDs of the items they are joining. If the join tables had additional properties, such as DateCreated, the EDM would have created entities for them.
Building Assembly
When a project containing an EDMX is compiled, the compiler extracts the StorageModels, ConceptualModels, and Mappings sections of the EDMX file and creates individual schema files from them. In this case, the files are BAModel.ssdl,
BAModel.csdl, and BAModel.msl. By default, these files are embedded into the assembly that is built from the project.
If you look at the metadata portion of the EntityConnection string that the Entity Data Model Wizard inserted into the app.config file, you’ll see the following notation:
res://*/BAModel.csdl|res://*/BAModel.ssdl|res://*/BAModel.msl
Much of the functionality in the Entity Framework depends on its ability to read the schema files. The * in the metadata of the connection string indicates that you can find the files in an assembly. Entity Framework will search
all loaded assemblies until it finds the one with these embedded files.
相关文章推荐
- Note On <Programming Entity Framework 2nd Edition> -01: How to Use LINQPad 4.5
- Note On <Programming Entity Framework 2nd Edition> -03
- Note On <Programming Entity Framework 2nd Edition> -02: How to Use SqlExpress Profiler 2.0
- Note On <Programming Entity Framework 2nd Edition> -05
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 04
- Note On <Beginning ASP.NET 3.5> Chp 10 & <Professional ASP.NET 3.5 SP1 Edition> Chp 19
- Note on <C# 3.0 UNLEASHED With the .NET Framework 3.5> - 02
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 01
- Note on <Zend Framework - A Beginner's Guide> - 04 使用Doctrine初体验
- Note on <C# 3.0 UNLEASHED With the .NET Framework 3.5> - 01
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 03
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 02
- Note on <Beginning Microsoft SQL Server 2012 Programming> - 05
- Note on <Zend Framework - A Beginner's Guide> - 07
- [Entity Framework书籍推荐]Programming Entity Framework 2nd Edition vs Code First Edition
- <Introduction to Java Programming> Note 01
- Note on <Pro ASP.NET MVC 4> - 01
- Note on <Zend Framework - A Beginner's Guide> - 01:Apache的URL重寫,ZF項目結構
- Note on <Zend Framework - A Beginner's Guide> - 03
- Note On <Pro AngularJS> - 01