Map smallint column to byte field?

Map smallint column to byte field?

Postby markwatson » Fri 30 Mar 2012 16:03

HI,

I am currently evaluating dotConnect for PostgreSQL. I am using Entity Framework 4.3.1 with DbContext (Database first), and I was wondering if there was support for mapping a smallint column in PostgreSQL to a System.Byte field on an entity?

When I map a smallint field to an Int16 I have no issues. When I update my model in the designer (or update the CSDL directly) to map the same column to a Byte field I get the following error when attempting to load from the database:

Code: Select all
Unhandled Exception: System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at Devart.Data.PostgreSql.h.af(Byte[] A_0, Int32 A_1, Int32 A_2)
   at Devart.Common.r.ap(Byte[] A_0, Int32 A_1, Int32 A_2)
   at Devart.Data.PostgreSql.aj.ap(Byte[] A_0, Int32 A_1, Int32 A_2)
   at Devart.Data.PostgreSql.PgSqlDataReader.GetByte(Int32 i)
   at Devart.Data.PostgreSql.Entity.i.a(Int32 A_0)
   at Devart.Common.Entity.bc.GetValue(Int32 ordinal)
   at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
   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.RowNestedResultEnumerator.MoveNext()
   at System.Data.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.TryReadToNextElement()
   at System.Data.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.ReadElement()

   at System.Data.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)


My SSDL for this particular column looks like this:

Code: Select all


...and the CSDL looks like this:

Code: Select all


I am running PostgreSQL 9.1 and version 5.80.332.0 of dotConnect.

Is there something simple I'm missing?

Thanks!

-Mark
markwatson
 
Posts: 4
Joined: Fri 30 Mar 2012 15:43

Update

Postby markwatson » Mon 02 Apr 2012 20:51

I found in the help that the type in the SSDL should be set to "byte" (http://www.devart.com/dotconnect/postgresql/docs/DataTypeMapping.html), but after making this change I now get the following error:

Code: Select all
Unhandled Exception: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.NotSupportedException: Specified method is not supported.
   at Devart.Data.PostgreSql.c.a(DbType A_0)
   at Devart.Data.PostgreSql.PgSqlParameter.set_DbType(DbType value)
   at Devart.Common.Entity.bu.c(DbParameterBase A_0, c A_1)
   at Devart.Common.Entity.bu.d(DbParameterBase A_0, c A_1)
   at Devart.Common.Entity.bu.a(DbParameterBase A_0, c A_1)
   at Devart.Common.Entity.bu.a(ar A_0)
   at Devart.Common.Entity.a8.a(ar A_0)
   at Devart.Data.CommandTrees.ar.a(ad A_0)
   at Devart.Common.Entity.t.a(h A_0, DbCommand A_1)
   at Devart.Common.Entity.ao.a(h A_0, DbCommandBase A_1)
   at Devart.Common.Entity.ao.c()
   at Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices.a(DbCommandTree A_0, ax A_1)
   at Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices.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)
   --- End of inner exception stack trace ---
   at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
   at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
   at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator,EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter adapter)
   --- End of inner exception stack trace ---
   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(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()


My SSDL..

Code: Select all


Any thoughts?

Thanks,
Mark
markwatson
 
Posts: 4
Joined: Fri 30 Mar 2012 15:43

Postby Shalex » Tue 03 Apr 2012 14:24

markwatson wrote:My SSDL for this particular column looks like this:
Code: Select all

...and the CSDL looks like this:
Code: Select all

This works in our environment. Save your model after these settings and run the project again.
If this doesn't help, please send us your small test project with the corresponding DDL/DML script so that we can reproduce the issue in our environment.
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Postby markwatson » Tue 03 Apr 2012 16:42

Thanks! The test project is on its way.

In further testing I have found that I can retrieve data from the database in the same context as which it was saved, but when I attempt to load it in a new context it fails.

I appreciate the help.

-Mark
markwatson
 
Posts: 4
Joined: Fri 30 Mar 2012 15:43

Postby Shalex » Wed 04 Apr 2012 14:30

We have answered you by e-mail.
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Postby Shalex » Tue 10 Apr 2012 14:45

The bug with the PgSqlDataReader.GetByte method when reading data from smallint column is fixed. We will post here when the corresponding build of dotConnect for PostgreSQL is available for download.
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Postby Shalex » Thu 12 Apr 2012 14:38

New build of dotConnect for PostgreSQL 5.80.341 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://www.devart.com/forums/viewtopic.php?t=23888 .
Shalex
Devart Team
 
Posts: 7654
Joined: Thu 14 Aug 2008 12:44

Postby markwatson » Thu 12 Apr 2012 20:30

Works great. Thanks for the quick turnaround!

-Mark
markwatson
 
Posts: 4
Joined: Fri 30 Mar 2012 15:43


Return to dotConnect for PostgreSQL