验证输入到导航属性中的数据 [英] Validate data input into the navigation properties

查看:51
本文介绍了验证输入到导航属性中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何验证导航属性中的数据。

b

示例: 产品.Ingredients.Add(new
Ingredient())


如何确认所有成分是否都在那里在使用SaveChanges()之前的数据库?


< p style ="text-align:left"> 即使我使用存储库,开发人员也可以设置新的成分使用Product.Ingredient,因此存储库不是我的用户。


有人可以帮帮我吗?




http: //www.linkedin.com/pub/murilo-kunze/44/191/455

解决方案

你可以在您的存储库中公开SaveChanges()方法,该方法隐藏了context.SaveChanges()方法,并且可以在调用context.SaveChanges()之前执行其他检查。


I would like to know how to validate data in navigation properties.

Example:Product.Ingredients.Add(new Ingredient())

How can I verify if all ingredients is there at database before using SaveChanges()?

Even if I use a repository, a developer can set a new Ingredient using Product.Ingredient, so repository is not my anwser.

Can someone help me?


http://www.linkedin.com/pub/murilo-kunze/44/191/455

解决方案

You could expose a SaveChanges() method in your repository that hides the context.SaveChanges() method and can do additional checks before calling context.SaveChanges().


这篇关于验证输入到导航属性中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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