2015-12-15 50 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進行更改。之後,更新您的模型的屬性類型。乾杯!