2015-12-15 2 views
1

Я создал модель (edmx), подключающуюся к базе данных sqlite (не по выбору). У меня проблемы с логическими полями. Когда я запрашиваю таблицу с помощью браузера DB для SQLite, поля «boolean» имеют «t» или «f». Когда я называю веб-апи URL, он возвращает:Entity Framework Database first и SQLite Boolean error

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

OK после копания немного больше ... даже если столбцы заполнены «t» или «f» ... объект сущности возвращает нулевые значения для столбца ... – scruse24

ответ

0

OK - после того, как много копать, я нашел ответ. Вам нужно будет изменить тип свойства в файле EDMX. Щелкните правой кнопкой мыши на файле EDMX и нажмите «открыть с ...». Откройте файл с помощью редактора xml. Вам нужно будет найти свойство и изменить тип (я изменил свою строку на строку, так как столбцы «t» и «f»). Вам также необходимо внести изменения для scalarProperty. После этого обновите свой тип свойства модели. Ура!

Смежные вопросы