Specifies Cast is not valid - Precision Issue

Posts   
 
    
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 08-May-2012 22:10:53   

Hi,

I am using LLBlGen Pro 3.1, SQL 2008 & Oracle 11ii.

According to this thread , http://llblgen.com/tinyforum/Messages.aspx?ThreadID=3029

I have created following columns.

Oracle SQL .Net Type

X NUMBER(5,0) X [int] System.Int32

But i am getting "Specifies Cast is not valid." I have also found out that in LLBlGen, Precision for both are different.

Oracle 5,0 SQL 10,0

Why there is difference in precision and scale where there is same .net type for both of them. Can you guide me on this.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-May-2012 22:20:17   

In SQL Server, the int data type has a precision of 10, and a scale of 0. ANd in Oracle you have specified a precision of 5, and scale of 0.

So it's normal that you find differences. If you want compatability, define the Oracle field to be Number(10,0)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 09-May-2012 10:04:48   

Actually, NUMBER(9,0), as ODP.NET converts a NUMBER(9,0) to int, and a NUMBER(10,0) to decimal. disappointed

NUMBER(5,0) results in an int16.

Frans Bouma | Lead developer LLBLGen Pro
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 09-May-2012 19:54:20   

Hi,

I have tried Number(9,0) but it didn't worked for me. I am explaining here my problem again in little more detail.

I am getting "Specific Cast is not valid." exception when i am doing fetch entity.

LLBLGen generated code property:

public virtual System.Int32 EmploymentStatus { get { return (System.Int32)GetValue((int)EmpGeneralFieldIndex.EmploymentStatus, true); } set { SetValue((int)EmpGeneralFieldIndex.EmploymentStatus, value); } }

Field definition Of Employment Status

SQL Server - Int Oracle - Number(9,0)

Please see attachment for llblgen mapping details.

I have mapped sql server first and then added oracle. This error is only happening in oracle. your input is greatly appreciated.

Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 09-May-2012 19:56:20   

Hi,

I have tried Number(9,0) but it didn't worked for me. I am explaining here my problem again in little more detail.

I am getting "Specific Cast is not valid." exception when i am doing fetch entity.

LLBLGen generated code property:

public virtual System.Int32 EmploymentStatus { get { return (System.Int32)GetValue((int)EmpGeneralFieldIndex.EmploymentStatus, true); } set { SetValue((int)EmpGeneralFieldIndex.EmploymentStatus, value); } }

Field definition Of Employment Status

SQL Server - Int Oracle - Number(9,0)

Please see attachment for llblgen mapping details.

I have mapped sql server first and then added oracle. This error is only happening in oracle. your input is greatly appreciated.

Attachments
Filename File size Added on Approval
llblgenmapping.docx 285,139 09-May-2012 19:56.32 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-May-2012 19:57:39   

Nothing is attached.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-May-2012 09:06:06   

In your Oracle DB you have NUMBER(5,0) which ODP will retrieve as Int16. At your LLBLGen project the mapping was created as NUMBER(9,0) because originally your SQLServer type was int, so to match the types the model-first mapping was created as Number(9,0) in Oracle mappings to achieve the target type of Int32. This is normal.

Options:

A. Change your Oracle DB type to Number(9,0). B. Change the Oracle field mapping to Number(5,0), which is actually your type on the DB. But then a validation error will popup on LLBLGen Designer as the DB type and your .net type won't match. So you will have to create your own typeConverter that converts from Int16 to Int32. Then assign that typeConverter to that field. C. Change your SQLSerer mapping to Int16 and create a typeConverter for that field on SQLServer.

Option B will potentially raise Overflow/InvalidCast exceptions as well in your TypeConverter, as your Oracle DB type can't store Int32 values. So option A or C is preferred.

David Elizondo | LLBLGen Support Team
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 10-May-2012 15:11:40   

I can see it is attached. Why you cant see that. I am attaching one more time. If you cant see that download from this link.

http://dl.dropbox.com/u/7290619/llblgenmapping.docx

Attachments
Filename File size Added on Approval
llblgenmapping.docx 285,139 10-May-2012 15:11.48 Approved
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 10-May-2012 15:16:41   

Well, I have changed my oracle datatype to number(9,0) and sql to int. So Both are having ODP Int32. But then also some how precision for this both values are different. SQL Server has precision of (10,0) where as oracle having 9,0. I don't understand having same ODP type both sql and oracle then also i am having this issue. Please see attachment for more detail.

http://dl.dropbox.com/u/7290619/llblgenmapping.docx

daelmo wrote:

In your Oracle DB you have NUMBER(5,0) which ODP will retrieve as Int16. At your LLBLGen project the mapping was created as NUMBER(9,0) because originally your SQLServer type was int, so to match the types the model-first mapping was created as Number(9,0) in Oracle mappings to achieve the target type of Int32. This is normal.

Options:

A. Change your Oracle DB type to Number(9,0). B. Change the Oracle field mapping to Number(5,0), which is actually your type on the DB. But then a validation error will popup on LLBLGen Designer as the DB type and your .net type won't match. So you will have to create your own typeConverter that converts from Int16 to Int32. Then assign that typeConverter to that field. C. Change your SQLSerer mapping to Int16 and create a typeConverter for that field on SQLServer.

Option B will potentially raise Overflow/InvalidCast exceptions as well in your TypeConverter, as your Oracle DB type can't store Int32 values. So option A or C is preferred.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-May-2012 20:08:08   

Dropbox document doesn't open.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 11-May-2012 11:05:39   

Precision is ignored for ints anyway in the MODEL side. So for Oracle, you need to specify a precision as that's important for the NUMBER -> .net type conversion performed by ODP.NET.

So you specify int in the entity, and in sqlserver you specify 'int' as type and in oracle you specify NUMBER(9, 0) as type.

As the value coming out of either database is an int32, this won't go wrong. If you still get a problem, please examine when it happens and what the exact value is (type) that's inside the field (the field's CurrentValue property has the real value).

Btw, next time, just attach the image instead of attaching a word doc.

Frans Bouma | Lead developer LLBLGen Pro
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 23-May-2012 21:21:01   

Sorry, but i am thinking you did not get my question so i am posting again here.

I am using LLBlGen Pro 3.1, SQL 2008 & Oracle 11ii.

I have created following columns.

Oracle SQL .Net Type

X NUMBER(9,0) X [int] System.Int32

LLBlGen Precision for both are different ( Check attachment for details)

Oracle 9,0 SQL 10,0

I am getting "Specifies Cast is not valid." Exception. Can you tell me how to resolve this issue?

Attachments
Filename File size Added on Approval
Mapping.png 368,687 23-May-2012 21:27.41 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-May-2012 08:48:00   

I have similar test and I can't reproduce such exception. When and how do you get that exception? (fetching from oracle or from SqlSever?) Also please post the exact exception message and stack trace.

David Elizondo | LLBLGen Support Team