Convert hstore column to a XPO class property Npgsql 3.2.7 - npgsql

We have upgraded Npgsql from 2.2.5 to 3.2.7.
We have a database column of type hstore.
In 2.2.5
this column used to be converted by a XPO valueconverter
from a string that came from the database
to a List < Tuple< object, object>> that we wanted in a XPO class.
Before 3.2.7 something has changed
and when we try to read this column,
we get an error stating that "an object should implement IConvertible".
But it does not state, which object should be IConvertible.
I presume that this is the target XPO property,
of type List< Tuple< object,object>>
We have tried to change the property to IConvertible but without effect.
Has anybody had similar problems with the hstore type and the 3.* upgrade?

I have no idea exactly what your application does (or how XPO works), but Npgsql 3.x returns PostgreSQL hstore as Dictionary<string,string>. It seems like your client code (XPO?) may be expecting the value returned by Npgsql to be IConvertible, which isn't the case anymore.

OK, I got it. The change of the type read from the database from string to Dictionary has caused errors in XPO that does not handle it properly. Just in case somebody else encounters this issue: One needs to subclass PostgreSqlConnectionProvider and override the ReformatReadVaue() method to omit Dictionary. Second thing is a proper value converter for the property. https://www.devexpress.com/Support/Center/Question/Details/T614674/problem-with-hstore-fields-after-upgrading-from-16-2-to-17-2
Thank you again for pointing me at the right direction.

Related

Null parameter values in Npgsql 3.x

My ORM does not know the type for a null NpgsqlParameter value at runtime. In Npgsql 2.x I could simply set
parameter.value = DBNull.Value
and this was all good. Now it seems I have to set a DbType too, but I don't know what the type's supposed to be, so I can't set it.
In 2.x it seems to be defaulting to String/text, but setting that explicitly in 3.x causes type exceptions.
What can I do, without having to modify all my SQL?
Is there a default DbType that will give the 2.x behaviour?
Can you try setting NpgsqlDbType to NpgsqlDbType.Unknown?

DataBinding error -DataGridView in Winforms

I'm new to VB.NET, Windows Application, and DataGridView.
This is a very basic error which I'm suffering now. I have a stored procedure to retrieve data from the database. I stored those data in a DataSet and tried to view it in a DataGridView. I used this code for databinding which is throwing the error:
DataGridView1.DataSource=ds
DataGridView1.DataBindings()
The second line in the code is throwing an error:
Property access must assign to the property or use its value.
How can I solve this?
There is no DataGridView1.DataBindings() when dealing with Winforms, it's practical in Webforms.
Just remove the last line and leave the following:
DataGridView1.DataSource=ds
Perhaps you meant:
DataGridView1.DataSource=ds
DataGridView1.DataBind()
EDIT :
You haven't provided enough code to check that everything is in place, but I suggest you work your way through this: http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx
use DataGridView1.Databind()
hope that helped...

DataContract IsReference only working one way?

I have a base class from which all my model classes inherit - Entity. Entity is decorated with
[DataContract(IsReference = true)]
That worked with going from client to server (a save operation). But I'm now getting the same error I was before I added IsReference when going from server to client (a get operation). Any ideas?
Edit:
The error is:
There was an error while trying to
serialize parameter
http://tempuri.org/:GetResult. The
InnerException message was 'Object
graph for type
'Current.Entities.LazyList`1[[Current.Entities.SubPart,
Current.Entities, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null]]' contains cycles
and cannot be serialized if reference
tracking is disabled.'. Please see
InnerException for more details.
Edit:
Shoot, I answered this but have since deleted it. I thought I fixed it due to something else I did in the project. I was wrong, this is still causing me an issue. I have a little bit more information - the server-to-client error only happens if an entity in the object graph contains a non-empty LazyList of children. If the list is empty then there's no problem.
Enabling the http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.preserveobjectreferences.aspx flag should fix this. (The flag also exists on DataContractSerializerOperationBehavior -- in config, via the DataContract attribute, and via any custom behaviors you inherit)

Using a Guid Version column in NHibernate

We are working with a legacy database that uses SQL server uniqueidentifier columns for concurrency hence we need to use a Guid as a version column. Any idea how we could achieve this in NHibernate?
We're currently defining our mapping using Fluent NHibernate as a Guid typed property called ConcurrencyId using this snippet
Version(x => x.ConcurrencyId)
This results in the following error when creating a session
System.InvalidCastException : Unable to cast object of type 'NHibernate.Type.GuidType' to type 'NHibernate.Type.IVersionType'.
Any ideas on how this could be done, fluently or otherwise would be appreciated. We're happy to hack the source if it can be made to work.
You could try implementing a custom type implementing NHibernate.UserTypes.IUserVersionType. (I think this suggestion may pertain to a newer version of NHibernate than you are using.)
Check this...
http://ayende.com/Blog/archive/2009/04/15/nhibernate-mapping-concurrency.aspx
and the docs for the version property
http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-version
Looks like you can't use a Guid for this. Maybe just map it as a property and handle the version checks yourself.

How do you reference a field in the Embedded Code of an SSRS report

Is there a proper way to reference the fields of a ssrs report from the embedded code of an ssrs report?
When I try to use Fields!Program.Value I get the following error --
There is an error on line 3 of custom code: [BC30469]
Reference to a non-shared member requires an object reference.
Upon googling I found you could reference the Parameters of a report by prepending Report. at the beginning. So I tried this Report.Fields.Program.Value.
That results in the following error...
There is an error on line 3 of custom code: [BC30456] 'Fields' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode'.
So... in summary, is there a way to reference the fields from the embedded code. I figured out I could pass the field vals to the function itself but I would prefer to reference the fields directly.
Seth
You have to pass it in as a parameter.
=Code.ToUSD(Fields!StandardCost.Value)
You do have two other alternatives to passing by parameter, though neither is very pretty.
(Beware! After I wrote the following paragraph I discovered defaults from queries are not supported in local processing mode so this first solution may not be viable for you as it was not for me.)
You can create a hidden report parameter with a default value set from a dataset, then reference this with the Report.Parameters!MyParam.Value syntax. You have to be careful when testing this, as (at least in BI studio 2005) the report parameters don't seem to get reliably re-initialised from the DB in the Preview tab.
Alternatively you can create a hidden textbox on the report with its text set from a dataset, and then reference the textbox from code. In this case you have to pass the ReportItems object as a parameter, but the slight advantage is that it is only ever one extra parameter. Be sure to strongly type the parameter when declaring it:
public Sub MyCustomCode(ri as ReportItems)
The code will work in BI studio without the type declaration but for me it caused errors with the report viewer control in local processing mode if 'as ReportItems' was not present.
In either case, this is only really useful for page level data, so functions for use in a table should still take parameters.

Resources