无法在EF4中保存空白/空字符串字段值? [英] Can't save blank/empty string field values in EF4?

查看:299
本文介绍了无法在EF4中保存空白/空字符串字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的团队正在开发EF4,我们遇到了陷入困境的障碍。

Our team is developing in EF4 and we have run into a snag that is turning into a showstopper.

我们在Sliverlight 4应用程序中使用EF4(使用VS2K10)并连接到现有的SQL Server数据库。我们在几个实体中发现的是我们无法将空白字符串保存到数据库中。当我们尝试保存具有字符串
字段的实体时,其后备存储区域定义为NOT NULL,如果字段值不包含某种值,则尝试插入或更新会生成错误。 EF4几乎似乎将空字符串转换为NULL(尽管实体
中的列定义明确地说"Nullable =" false")。尝试使用设置为string.Empty的字符串属性值进行保存,"""或" "都给出了相同的结果。我们*没有*指定"RequiredField"这些属性的数据注释,但结果似乎模仿该注释的
行为(如果我理解文档)。

We're using EF4 in a Sliverlight 4 app (using VS2K10) and connecting to an existing SQL Server database. What we have discovered with several of our entities is that we cannot save blank strings to the database. When we try to save an entity that has a string field whose backing store is defined NOT NULL, if the field value does not contain some sort of value then an attempt to insert or update generates an error. EF4 almost seems to convert blank strings to NULL (despite column definitions in the entity that explicitly say "Nullable="false"). Attempts to save with a string property value set to string.Empty, "" or " " all give the same result. We have *not* specified the "RequiredField" data annotation on these properties but the result seems to mimic the behavior of that annotation (if I understand the docs).

什么给出?我们不知道EF中有一些全球性的环境吗?在某些地方,我们已经能够通过设置"虚拟"来解决这个问题。字符串值,但更改所有受影响的列以允许NULL不是真正的选项。

What gives? Is there some global setting in EF we don't know about? In some places we've been able to work around the issue by setting a "dummy" string value but changing all affected columns to allow NULL isn't really an option.

感谢您的任何见解。

杰夫

推荐答案

我原来帖子的更新:我在调试我们的Silverlight 4应用程序时运行了SQL Server分析器,因为我尝试了一个应该运行的操作导致db上的INSERT。我在向EF4提交操作时收到错误消息,
部分 "" ;;请检查EntitiesInError中每个实体的Entity.ValidationErrors以获取更多信息。"在进入SQL客户端之前,EF已停止该操作;在探查器中没有显示任何内容。

An update to my original post: I just ran SQL Server profiler while debugging our Silverlight 4 app, as I tried an operation that should have resulted in an INSERT on the db. I got an error when submitting the operation to EF4 with the message, in part "... Please inspect Entity.ValidationErrors for each entity in EntitiesInError for more information." The operation was stopped by EF before it got to the SQL client; nothing showed up in the profiler.

Soooo ......这个问题肯定是我们需要覆盖的EF内部的某种验证(如果可能的话)。什么是"魔术"设置是否需要添加以允许空白字符串?

Soooo... The issue is definitely some sort of validation going inside EF that we need to override (if possible). What "magic" setting do I need to add to permit blank strings?

Jeff


这篇关于无法在EF4中保存空白/空字符串字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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