替代数据库存储数据? [英] Alternative to database for storing data?

查看:92
本文介绍了替代数据库存储数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用SQL Server Compact Edition(本地数据库)。但是,当我使用实体框架,我不断遇到一个非常恼人的UpdateException。我的数据库只有两个小表有外键关系链接在一起。所以我问,是否有任何替代数据库?还是这是唯一的选择?

UPDATE:

这里是EDMX映射。

以下是异常的stacktrace:
System.Windows.Markup.XamlParseException未处理
消息=不能创建在Assembly AssignmentOrganizer,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'中定义的'MainWindow'的实例。调用的目标抛出了异常。标记文件AssignmentOrganizer;组件/ MainWindow.xaml中的错误,第1行第9位。
Source = PresentationFramework
LineNumber = 1
LinePosition = 9
StackTrace:
System.Windows.Markup.XamlParseException.ThrowException(字符串消息,异常的InnerException,的Int32 LINENUMBER,的Int32 linePosition,乌里基本URI,XamlObjectIds currentXamlObjectIds,XamlObjectIds contextXamlObjectIds,类型的objectType)
在System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext,的Int32 LINENUMBER,的Int32 linePosition,字符串消息,异常的InnerException)
在System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(字符串消息,异常的InnerException)
在System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(类型类型,Int16 typeId,Boolean throwOnFail)
在System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamIElementStartRecord bamlElementStartRecord,Object& element,ReaderFlags&标志,类型& delayCreatedType,Int16& delayCreatedTypeId)
在System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在System.Windows.Markup.BamlRecordReader .ReadRecord(bamlRecord bamlRecord)
在System.Windows.Markup.BamlRecordReader.Read(布尔singleRecord)
在System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
在System.Windows.Markup .TreeBuilder.Parse()
在System.Windows.Markup.XamlReader.LoadBaml(流流,ParserContext parserContext,对象的父母,布尔closeStream)
在System.Windows.Application.LoadBamlStreamWithSyncInfo(流流,ParserContext pc)
在System.Windows.Application.LoadComponent(Uri resourceLocator,Boolean bSkipJournaledProperties)
在System.Windows.Application.DoStartup()
在System.Windows.Application。<。.ctor> ; b__0(Object unused)
在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Boolean isSingleParameter)
在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source,Delegate callback ,Object args,Boolean isSingleParameter,Delegate catchHandler)
在System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象args,布尔isSingleParameter,委托catchHandler)
在System.Windows.Threading.DispatcherOperation。 InvokeImpl()
在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)
在System.Threading.ExecutionContext.runTryCode(对象userData)
在System.Runtime.CompilerServices.RuntimeHelpers。 ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,用户数据对象)的System.Threading.ExecutionContext.RunInternal
(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态)在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback
回调,对象状态)
在System.Windows.Threading.DispatcherOperation.Invoke()
在System.Windows.Threading.Dispatcher.ProcessQueue()
在System.Windows.Threading.Dispatcher。 WndProcHook(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&处理)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,IntPtr lParam,Boolean& processed)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,布尔isSingleParameter)
在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象args,布尔isSingleParameter,委托catchHandler )
在System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调,对象args,布尔isSingleParameter,委托catchHandler)
在System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority优先级,TimeSpan超时,委托方法,对象args,布尔isSingleParameter)
在System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority优先级,代理方法,对象arg)
在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg ,IntPtr wParam,IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher .Run()
在System.Windows.Application.RunDispatcher(对象忽略)
在System.Windows.Application.RunInternal(窗口窗口)
在System.Windows.Application.Run窗口)
在System.Windows.Application.Run()
at AssignmentOrganizer.App.Main()在C:\Users\Mohit\Documents\Visual Studio 2010\Projects\ AssignmentOrganizer \AssignmentOrganizer\obj\x86\Debug\App.g.cs:line 0
在System.AppDomain._nExecuteAssembly(Assembly程序集,String [] args)
在System.AppDomain .ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)
在System.Threading.ThreadHelper.ThreadStart()
InnerException:System.Reflection.TargetInvocationException
Message = Exception已被调用的目标抛出。
Source = mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandle& ctor,Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean fillCache)
在System.RuntimeType.CreateInstanceImpl(Boolean publicOnly,Boolean skipVisibilityChecks,Boolean fillCache)
at System.Activator.CreateInstance(Type type,Boolean nonPublic)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type,Int16 typeId,Boolean throwOnFail)
InnerException:System.Data.UpdateException
Message =更新条目时发生错误。有关详细信息,请参阅InnerException。
Source = System.Data.Entity
StackTrace:
在System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器)
在System.Data .EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
在System.Data.Objects.ObjectContext.SaveChanges(布尔值acceptChangesDuringSave)
在System.Data.Objects.ObjectContext.SaveChanges()
at AssignmentOrganizer .App_Data.AssignmentRepository.CreateAssignment(Assignment assignmentToCreate)in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\App_Data\AssignmentRepository.cs:line 20
at AssignmentOrganizer.MainWindow..ctor()in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 34
InnerException:System.Data.EntityCommandCompilationException
Message =准备命令定义时发生错误。有关详细信息,请参阅内部异常。
Source = System.Data.Entity
StackTrace:
在System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
在System.Data.Mapping。 Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator,Dictionary
2 identifierValues)
在System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator,EntityConnection connection,Dictionary 2 identifierValues,List 1 generatedValues)
在System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器)
InnerException:System .NotSupportedException
Message = SQL Server Compact不支持服务器生成的密钥和服务器生成的值。
Source = System.Data.SqlServerCe.Entity
StackTrace:
在System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateReturningSql(StringBuilder commandText,DbModificationCommandTree树,ExpressionTranslator转换器,DbExpression返回)
at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree,List 1& parameters,Boolean isLocalProvider)
在System.Data.SqlServerCe.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree,List
1& parameters,CommandType& commandType,Boolean isLocalProvider)
在System.Data.SqlServerCe.SqlCeProviderServices.CreateCommand(DbProviderManifest providerManifest,DbCommandTree commandTree)
at System.Data .SqlServerCe.SqlCeProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest,DbCommandTree commandTree)
在System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
在System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
InnerException:
`

I was using SQL Server Compact Edition (local-database) for my application. But while I was using the entity framework, I kept experiencing a very annoying UpdateException. My database only has two small tables with a foreign key relationship linking them together. So I am asking if there is any alternative to a database? Or is that the only option?
UPDATE:
Here is the EDMX map.
Here is the stacktrace for the exception: System.Windows.Markup.XamlParseException was unhandled Message=Cannot create instance of 'MainWindow' defined in assembly 'AssignmentOrganizer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'AssignmentOrganizer;component/MainWindow.xaml' Line 1 Position 9. Source=PresentationFramework LineNumber=1 LinePosition=9 StackTrace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType) at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException) at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException) at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail) at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId) at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord) at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord) at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord) at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord) at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() at System.Windows.Markup.TreeBuilder.Parse() at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc) at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties) at System.Windows.Application.DoStartup() at System.Windows.Application.<.ctor>b__0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at AssignmentOrganizer.App.Main() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\obj\x86\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.Reflection.TargetInvocationException Message=Exception has been thrown by the target of an invocation. Source=mscorlib StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail) InnerException: System.Data.UpdateException Message=An error occurred while updating the entries. See the InnerException for details. Source=System.Data.Entity StackTrace: at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave) at System.Data.Objects.ObjectContext.SaveChanges() at AssignmentOrganizer.App_Data.AssignmentRepository.CreateAssignment(Assignment assignmentToCreate) in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\App_Data\AssignmentRepository.cs:line 20 at AssignmentOrganizer.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 34 InnerException: System.Data.EntityCommandCompilationException Message=An error occurred while preparing the command definition. See the inner exception for details. Source=System.Data.Entity StackTrace: at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree) at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary2 identifierValues) at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List1 generatedValues) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) InnerException: System.NotSupportedException Message=Server-generated keys and server-generated values are not supported by SQL Server Compact. Source=System.Data.SqlServerCe.Entity StackTrace: at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, ExpressionTranslator translator, DbExpression returning) at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, List1& parameters, Boolean isLocalProvider) at System.Data.SqlServerCe.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, List1& parameters, CommandType& commandType, Boolean isLocalProvider) at System.Data.SqlServerCe.SqlCeProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree) at System.Data.SqlServerCe.SqlCeProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree) at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree) InnerException: `

推荐答案

总有替代品。问题是他们是否比数据库更好。您可以将数据存储为XML或自己的文件格式等。然后,您必须编写适当的查询,更新代码等。可能很好 - 但我们不能说没有更多信息。

There are always alternatives. The question is whether they're better than a database. You could store your data in XML, or your own file format, etc. Then you'd have to write appropriate querying, updating code etc. That may be fine - but we can't possibly say without more information.

然而,在考虑另一个解决方案之前,我将了解为什么会看到异常。你可能有一些你没有真正预期的行为,当你改变了你的存储层,同样可能会伤害你 - 也许很难诊断在那一点。一旦你弄清楚为什么你当前的方法不工作,你会在一个更好的位置,知道它是否值得改变。

However, before even considering another solution, I would get to the bottom of why you're seeing an exception. You may well have some behavior you didn't really anticipate which could equally hurt you when you've changed your storage layer - and it may well be harder to diagnose at that point. Once you've worked out why your current approach isn't working, you'll be in a much better position to know whether or not it's worth changing.

这篇关于替代数据库存储数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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