High!
I use Devart.Data.Oracle.ICustomOracleObject to map my .NET object to Oracle Object via Attribute Mapping. I noticed that I have to name properties of my .NET object as they named in Database. Is there a way to avoid this limitation? May be, there is an attribute that i need?
Thanks!
CustomOracleObject mapping
Re: CustomOracleObject mapping
LinqConnect doesn't provide support for Oracle Objects.
Please see this topic for more information regarding working with Oracle Objects and dotConnect for Oracle: http://www.devart.com/dotconnect/oracle ... jects.html
Please see this topic for more information regarding working with Oracle Objects and dotConnect for Oracle: http://www.devart.com/dotconnect/oracle ... jects.html
Re: CustomOracleObject mapping
I guess, I did not properly explained my situation. By the way, I found out that problem was in bounding DataSource to asp.net server control. In console application everything works fine!
I have the following defined types and table in Database:
and the following code in console application:
may be this sample will be useful to someone/
I have the following defined types and table in Database:
Code: Select all
CREATE TYPE T_VARIANT AS OBJECT (
Value_Number Number(10),
Value_VARCHAR2 VARCHAR2(30)
);
CREATE TABLE TEST_VARIANT(
Name VARCHAR2(9),
Value T_VARIANT
);
Code: Select all
using Devart.Data.Oracle;
using System;
using System.Linq;
namespace DevartLinq
{
[System.Data.Linq.Mapping.ProviderAttribute(typeof(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))]
class MyContext : Devart.Data.Linq.DataContext
{
public MyContext(Devart.Data.Oracle.OracleConnection conn) : base(conn) { ObjectTrackingEnabled = false; }
}
[System.Data.Linq.Mapping.Table(Name = "TEST_VARIANT")]
class TestVariant
{
[System.Data.Linq.Mapping.Column(Name = "Name")]
public string Name { get; set; }
[System.Data.Linq.Mapping.Column(Name = "VALUE")]
public ValueType Value { get; set; }
}
class ValueType : Devart.Data.Oracle.ICustomOracleObject
{
public decimal ValueNumber { get; set; }
public string ValueVarchar2 { get; set; }
public void FromOracleObject(NativeOracleObject oraObject)
{
if (oraObject.GetOracleValue("VALUE_NUMBER") != DBNull.Value)
ValueNumber = Convert.ToDecimal(oraObject.GetOracleValue("VALUE_NUMBER"));
if (oraObject.GetOracleValue("VALUE_VARCHAR2") != DBNull.Value)
ValueVarchar2 = oraObject.GetOracleValue("VALUE_VARCHAR2").ToString();
}
public NativeOracleObject ToOracleObject(OracleConnection con)
{
throw new NotImplementedException();
}
}
class Program
{
static void Main(string[] args)
{
using (var conn = new Devart.Data.Oracle.OracleConnection() { Server = "TEST", UserId = "TEST", Password = "TEST" })
{
conn.Open();
using (var cont = new MyContext(conn))
{
OracleType.GetObjectType("T_VARIANT", conn).UdtType = typeof(ValueType);
Console.WriteLine(cont.GetTable<TestVariant>().First().Value.ValueNumber);
}
conn.Close();
conn.Dispose();
}
Console.ReadKey();
}
}
}
Re: CustomOracleObject mapping
Thank you for sharing the workaround.
Keep in mind, that we have made a major refactoring of the LinqConnect engine since version 4.0 (dotConnect for Oracle 7.0.6) and since this version the references to System.Data.Linq are removed, and LinqConnect uses only its own classes. So it is necessary to replace all occurrences of "System.Data.Linq." with "Devart.Data.Linq.".[System.Data.Linq.Mapping.ProviderAttribute(typeof(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))]
> class MyContext : Devart.Data.Linq.DataContext
> {...}