2

I am working on a project using Asp.net mvc 3 and planning to have oracle 11g database as back-end.

I was able to access oracle server with no problem and data loaded successfully into an html table.

The problem comes when I try to add, edit or delete a record. I believe it is a very simple issue, but till now, I couldn't figure it out. The following simple model is used:

class Country
{
    public int CountryId { get; set; }
    public string CountryName { get; set; }
}

The CountryId feild was created at Oracle using NUMBER(10) as I thought this will work as SQL Server Integer. But an exception was raised, indicates that it couldn't take the value as Edm.decimal !

I tried to make it NUMBER(19) and changed the CountryId to long and still getting the same exception.

I spent long hours searching for an open source project that is using asp.net mvc with oracle, but I couldn't find any!

Any idea, why oracle is not supporting integer, long? how to make it working as expected with my MVC project?

2 Answers 2

5

From Oracle Data Type Mappings,

This data type is an alias for the NUMBER(38) data type, and is designed so that the OracleDataReader returns a System.Decimal or OracleNumber instead of an integer value. Using the .NET Framework data type can cause an overflow.

So, you need to use decimal datatype in .net framework to support the NUMBER datatype in Oracle.

It would be better if you mapped your data type in following way:

[.NET: Int32] = [Oracle:NUMBER(2)..NUMBER(9)*] 
[.NET: Int64] = [Oracle:NUMBER(10)..NUMBER(18)*]
[.NET: Double] = [Oracle:NUMBER(x, 0)..NUMBER(x, 15)*]
[.NET: Double] = [Oracle: FLOAT]
[.NET: Decimal] = [Oracle:NUMBER] 
Sign up to request clarification or add additional context in comments.

4 Comments

I need to support C# integer, what Oracle data type should I use?
I don't know how to do that! is that C#?
I did, and got the exception. I tried decimal and it worked. So, no way to use int or long datatypes? The same application should work with SQL server at the same time.
Most prefers decimal over int or long datatype while working with oracle which I had already specified through the documentation part...
0

Have you tried using a decimal or an Int32? I am getting my suggestions from some documentation that I found online: http://docs.oracle.com/cd/E11882_01/win.112/e18754/featLINQ.htm . Let me know how this might work for you.

1 Comment

For @LolCoder answer, i think he is saying the value type can just be set to an Int64. Can you try that? Does that column in your database allow NULL values? If yes, maybe try either int?, decimal?, long?, Int32? or Int64?. The '?' means the value can be a null. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.