Conversion Issue with LLBLGEN Pro 3.1

Posts   
 
    
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 08-Dec-2011 23:11:18   

Hi,

I am using LLBLGEN Pro 3.1, Sql server 2008 & Oracle 11i

I am trying to retrieve values from sql and oracle database, sql works fine but oracle gives me error "Specified cast is not valid.".

Table Defined as follows..

SQL Oracle

Id - Int Number(10,0) Name - Varchar(64) Varchar(64)

LLBLGEN Mapping

SQL: Oracle

Id - long(System.Int64) long(System.Int64)

Database generic Code:

Method is defined like this...

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

Error at this line: "get { return (System.Int32)GetValue((int)RoleFieldIndex.Id, true); }"

Please guide me on this issue...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Dec-2011 06:12:43   

As far as I know, if you want Oracle column mapped to an int field you should define the column as NUMBER(x, 0), x between 6 and 9. So that might be the issue.

David Elizondo | LLBLGen Support Team
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 13-Dec-2011 20:25:44   

Is there is any other way to fix this issue? Does type conversion can help me? Please guide me on this.

Thanks

Rishi

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Dec-2011 21:18:43   

I don't understand why the error raises at the DBGeneric project while the type mapping is "long" for both SQLServer and Oracle.

The full exception message and stack trace would work to understand the root of the problem. I will try to create a repro case with that info and will come back to you later.

(Edit) I can't reproduce it using similar scenario. The .net long type should be generated as Int64, so I think you have something strange in your .llblgenproj. I'm attaching a tiny test project, see if you can reproduce the problem there.

Attachments
Filename File size Added on Approval
oracleAndSqlServerTest.zip 55,890 14-Dec-2011 06:30.36 Approved
David Elizondo | LLBLGen Support Team
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 14-Dec-2011 21:02:10   

I looked at your example, difference between your code and my is, you have defined SQL datatype as bigint whereas i have defined as Int and i am using "Sync Target Field with Model field" to remove type conversion error. Please guide me how i can handle this without changing anything in database. I have tried type converter, but it didn't helped me.

Rishi

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Dec-2011 06:41:11   

I see. When I setup the project I started from Model-first, then I just run the DB scripts. As the model type was long, it was mapped to bigint in SqlServer.

Now I changed the SqlServer DB type to int, then sync the model. At this point the Oracle mappings has a validation error because the model says it must be Int32 but the DB type (NUMBER(10,0)) is mapped to Int64. So indeed a TypeConverter should work here. I cooked a Int32-Int64 TypeConverter for you, it's attached with the other test files. The test are passing. The case when this could crash is when you have a very big value in your Oracle DB and it will try to put it in an Int32 object. So the best solution would be to put DB columns to the smaller type (INT for SS and NUMBER(9,0) for Oracle). But, as you wont modify DB types, this TypeConverter should work assuming that you wont store values bigger than NUMERIC(9,0) in your Oracle DB.

Let me know if this worked for you.

Attachments
Filename File size Added on Approval
oracleAndSqlServerTest.zip 32,847 15-Dec-2011 06:41.29 Approved
David Elizondo | LLBLGen Support Team
Rishi
User
Posts: 69
Joined: 31-Oct-2011
# Posted on: 15-Dec-2011 19:37:21   

Thanks.. this helped