从物化“System.Guid”类型到“System.Int32”类型的指定转换无效。
我们有几个 WCF 服务,它们具有 Multiple 并发模式和 Single 的 InstanceContextMode。我们的架构专注于使用基于构造函数的依赖注入(inject)的松散耦合模型。这又是使用 Unity 2.0 实现的(每个服务的 web.config 都在统一容器部分中定义的接口(interface)和类型之间进行映射)。我们的依赖项之一是使用 Entity Framework 4 与 MSSql Server 通信的 DAL 程序集(数据访问层)。与数据库对话的类也包含在统一映射中。
当我们运行集成测试时,一切都很好。但是,当我们转到性能环境以运行负载测试(2、3、4 个并发用户)时,我们开始看到以下错误:
System.InvalidOperationException:“Session”上的“auth_token”属性无法设置为“Int32”值。您必须将此属性设置为“Guid”类型的非空值。
使用以下堆栈:
at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at System.Linq.Queryable.First[TSource](IQueryable`1 source)
at MISoa.DataAccessLayer.Authentication.AuthenticationDB.RetrieveSession(Guid authToken)
at MISoa.DataAccessLayer.Authentication.AuthenticationAccess.RetrieveSession(String sessionToken)
这是罪魁祸首的方法:
public Session RetrieveSession(Guid authToken)
{
CheckDBContext();
var sessions = (from r in _dbContext.Sessions
where r.auth_token == authToken
select r);
return sessions.Count() > 0 ? sessions.First() : null;
}
CheckDBContext 方法只是检查数据库上下文是否为空,如果是,则抛出自定义异常。
emdx Session 实体对象具有以下公共(public)属性:
Guid auth_token
DateTime time_stamp
String user_id
String app_id
所以,看起来有时上面的 linq 从数据库返回一些其他对象,其中第一列是 int 而不是 guid?如果是这样 - 为什么?我有多个线程覆盖彼此的数据库上下文的问题吗?顺便说一句——我们将实例化数据库上下文的代码抽象为一个单独的类 (BaseDB),该类也由 unity 处理。所以,因为该服务是单例的,所以我为每个人准备了一个 BaseDB 实例,对吗?这是这里的问题吗?
哦,还有一件事。我们被告知我们将拥有 MSSql 2005,因此在 edmx 文件中我们拥有 ProviderManifestToken="2005"。但是我刚刚检查了一下,我们的性能数据库所在的服务器是 2008 版本。这是一个问题吗?
感谢您的帮助。
最佳答案
Do I have a problem with multiple threads overriding each other's db context?
是的。看这里:http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx
引用上面链接中黄色大框:
The
ObjectContextclass is not thread safe. The integrity of data objects in anObjectContextcannot be ensured in multithreaded scenarios.
您可能需要考虑将 [ThreadStaticAttribute] 放在您的 _dbContext 字段上。
关于c# - 从具体化 'System.Guid' 类型到 'System.Int32' 类型的指定转换无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10542055/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="