2015-12-15 49 views
1

我创建了一个连接到sqlite数据库(不是通过选择)的模型(edmx)。我遇到了布尔字段的问题。当我使用DB浏览器查询SQLite表时,'布尔'字段有“t”或“f”。当我调用web API URL,它返回:实体框架数据库第一和SQLite布尔错误

The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'. 


"ExceptionType": "System.ArgumentException", 
"StackTrace": " at System.Data.SQLite.SQLiteConvert.ToBoolean(String source) 
at System.Data.SQLite.SQLiteConvert.ToBoolean(Object obj, IFormatProvider provider, Boolean viaFramework) 
at System.Data.SQLite.SQLite3.GetBoolean(SQLiteStatement stmt, Int32 index) 
at System.Data.SQLite.SQLite3.GetValue(SQLiteStatement stmt, SQLiteConnectionFlags flags, Int32 index, SQLiteType typ) 
at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i) 
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetUntypedValueDefault(DbDataReader reader, Int32 ordinal) 
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) 
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName) 
at lambda_method(Closure , Shaper) 
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) 
at lambda_method(Closure , Shaper) 
at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) 
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext() 
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty) 
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) 
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) 
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding) 
at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding) 
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content) 
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()" 

我试图用这个答案What is easiest way to deal with converting 0/1 to False/True in EF 4.x?

由于做了(真/假)转换提前的帮助。

+0

确定挖掘多一点后...尽管列填充't'或'f'...实体对象正在为列返回空值... – scruse24

回答

0

好的 - 经过大量的挖掘,我找到了答案。您将需要更改EDMX文件中的属性类型。右键点击你的EDMX文件并点击'打开...'。用xml编辑器打开文件。您将需要找到属性并更改类型(由于列't'和'f'),我将其更改为字符串。您还需要对scalarProperty进行更改。之后,更新您的模型的属性类型。干杯!