Note On <Programming Entity Framework 2nd Edition> -04

50 篇文章 0 订阅
17 篇文章 0 订阅

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.





Really? How?
When a payment is updated, the database will automatically update the RowVersion field. The UpdatePayment procedure returns the new value.


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:

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.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值