column always NULL - custom column mapping

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

column always NULL - custom column mapping

Post by hepek » Tue 23 Apr 2013 18:49

I just downloaded the latest version of dotConnect. it looks like that version was released today(Apr 23)

I have extended entity and add a property like shown in a code below

Code: Select all

partial class ViewHomePage : BaseEntity {
   private string _cycleStatusDesc = null;

   [Column(Name = @"cycle_status_desc", Storage = "_cycleStatusDesc", DbType = "VARCHAR2(40) NOT NULL")]
   public string CycleStatusDesc {
      get {
         return _cycleStatusDesc;
      }
   }
}
later on in my code I populate a collection of ViewHomePage entities like this:

Code: Select all

var query = DB.ExecuteQuery<ViewHomePage>(sql).ToList();
the _cycleStatusDesc is always NULL even though it has a value in SQL behind.

this code always worked for me until today. Did you change the way you handle custom column mapping?

thanks

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: column always NULL - custom column mapping

Post by MariiaI » Thu 25 Apr 2013 11:02

We couldn't reproduce this issue. Please specify the following:
- the definition of the 'BaseEntity' entity class;
- the script for creating corresponding database table;
- the SQL script ('sql') you are performing;
- the data that should be stored in the database table.

If possible, please send us a test project with which this issue could be reproduced.

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Thu 25 Apr 2013 15:00

I discovered something that might be of importance to you.
When I move the code below from my partial extender class in DataContext.cs file to DataContextDesigner.cs (generated by devart) then it works fine. go figure!

Code: Select all

private string _cycleStatusDesc = null;

   [Column(Name = @"cycle_status_desc", Storage = "_cycleStatusDesc", DbType = "VARCHAR2(40) NULL")]
   public string CycleStatusDesc {
      get {
         return _cycleStatusDesc;
      }
   }
In another words if I trick devart into thinking that this column is part of the table everything works OK.
*remember this peace of code was working fine for me for 2 years, until I installed the latest version few days ago.

the SQL looks like this:

Code: Select all

SELECT V_OPL_HOME_PAGE.*, STATUS_DESCPN.name AS cycle_status_desc
FROM V_OPL_HOME_PAGE, STATUS_DESCPN
WHERE cycle_status    = cycle_status.status_code
AND job_number        = 124985
Last edited by hepek on Fri 26 Apr 2013 18:08, edited 1 time in total.

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Fri 26 Apr 2013 18:06

I have a feeling that problem is with a property attributes not being applied when property is declared in partial extender class.

[Column(Name=@"cycle_status_desc", Storage="_cycleStatusDesc", DbType="VARCHAR2(40) NULL")]

As I stated earlier when I move the property declaration to original class generated by devart it works ok.

I believe you should be able to reproduce it now.

BaseEntity is irrelevant here, but I will list it anyway

Code: Select all

public class BaseEntity {
      public bool IsTimeAdjusted { get; set; }
      public string TimeConversionExceptions { get; set; } 
      public long UserID { get; set; }
      public DbActionCodes DbAction { get; set; } 
      public decimal TempSortOrder { get; set; }
   }

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: column always NULL - custom column mapping

Post by MariiaI » Sat 27 Apr 2013 12:09

Thank you for the additional information. We have reproduced this behavior and it is an expected situation.
The problem is that the ViewHomePage class is not in fact mapped to a table (as your DataContext has no property of the Table<ViewHomePage> type). In this case, the Column mapping attribute has no effect, so the LinqConnect runtime accesses the CycleStatusDesc property (and not the _cycleStatusDesc field directly). Thus, you have to implement a setter of this property so that the query can fill it with data retrieved from the database.

Please change your class ViewHomePage in the following way:

Code: Select all

partial class ViewHomePage : BaseEntity {
   private string _cycleStatusDesc = null;
   public string CycleStatusDesc {
      get {
         return _cycleStatusDesc;
      }
      set {_cycleStatusDesc = value;}
   }
}
Please tell us if this helps.

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Tue 30 Apr 2013 14:45

Thank you for your answer Mariial,
But I don’t think you understand my point. I will resume, as clear as possible.

I have database view called V_OPL_HOME_PAGE, and I have a corresponding entity called ViewHomePage. I join two tables in my SQL like this:

Code: Select all

var sql = SELECT V_OPL_HOME_PAGE.*, STATUS.name AS cycle_status_desc 
FROM V_OPL_HOME_PAGE, STATUS ……
And then populate the results of SQL in List<ViewHomePage> like this:

Code: Select all

var query = myDataContext.ExecuteQuery<ViewHomePage>(sql).ToList(); 
In order to capture the value of column "cycle_status_desc" from my SQL, I created a partial class like this:

Code: Select all

partial class ViewHomePage {
   private string _cycleStatusDesc = null;

   [Column(Name = @"cycle_status_desc", Storage = "_cycleStatusDesc", DbType = "VARCHAR2(40) NULL")]
   public string CycleStatusDesc {
      get {
         return _cycleStatusDesc;
      }
   }
}
As you can see I mapped my new custom property to a column named “cycle_status_desc”. I expect my new property to be populated, but it is always null.

This logic worked for me for two years, and still does in production. Property “CycleStatusDesc” gets populated with “cycle_status_desc”.

After I installed the latest version of dotConnect released (Apr 23) the property CycleStatusDesc is not being populated at all and it is always null.

I hope I did a better job explaining my problem this time. Please escalate this if you need to.

thank you

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Tue 30 Apr 2013 15:25

It looks to me that column mapping attributes are not being applied, so dotConnect simply does not know how to map my new property and link it to a column from SQL.

Code: Select all

[Column(Name = @"cycle_status_desc", Storage = "_cycleStatusDesc", DbType = "VARCHAR2(40) NULL")]
Please note - when I (temporarily) move the code for my custom property declaration and place it in the original "ViewHomePage" class generated by dotConnect - it all works fine and CycleStatusDesc is being populated.

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Fri 03 May 2013 15:50

Any news on this issue?

The fact is you had certain functionality for years, and all of the sudden this functionality is gone with April 23th release.

It must be a bug. Can you at least acknowledge that problem exists and will be fixed in a future? That will make us feel better. Because of this bug we are unable to migrate to latest version of dotConnect, also unable to migrate to Visual Studio 2012.

Thank you

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: column always NULL - custom column mapping

Post by MariiaI » Tue 07 May 2013 14:26

As we have already told you before, the problem is that the ViewHomePage partial class is, in fact, not mapped to a table (as your DataContext has no property of the Table<ViewHomePage> type). In this case, the Column mapping attribute has no effect, so the LinqConnect runtime accesses the CycleStatusDesc property (and not the _cycleStatusDesc field directly) and, as this property has no setter, it is always NULL.
Please note, that when I (temporarily) move the code for my custom property declaration and place it in the original "ViewHomePage" class generated by dotConnect, it all works fine and CycleStatusDesc is populated.
In this case, the Column mapping attribute has effect due to the fact that the original "ViewHomePage" class generated by LinqConnect is mapped to a table and has the Table<ViewHomePage> type property (DataContext should 'know' which entities have to do with it), i.e.:

Code: Select all

public Devart.Data.Linq.Table<ViewHomePage> ViewHomePages
        {
            get
            {
                return this.GetTable<ViewHomePage>();
            }
        }
Thus, please do not use the column mapping attribute and add setter for the CycleStatusDesc property in the ViewHomePage partial class:

Code: Select all

partial class ViewHomePage {
   private string _cycleStatusDesc = null;
   public string CycleStatusDesc {
      get {
         return _cycleStatusDesc;
      }
      set {_cycleStatusDesc = value;}
   }
}
Besides, we are sending a small test project to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter.

As for the fact, that this scenario had worked with the earlier versions, we tested it with the previous version (4.2.229) and we got NULL as a result. Please send us a sample project, with which this scenario works with earlier versions, so that we could investigate it.

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Tue 07 May 2013 14:47

hi MariiaI,

Thank you for your answer. I did not receive your attachment due to corporate email policy.
I would appreciate if you make it available for download somehow for me.

I tried your suggestion to include a setter, but it makes no difference and custom property is still NULL. I can't wait to receive you sample project and see that code in action working. I don't understand how will dotConnect populate property when it does not know which SQL column to read from.

I will prepare a small project and email it to you. We use dotConnect 6.7 and the custom mapping works for us. I am pretty sure it also worked in version 5.

thank you for your help.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: column always NULL - custom column mapping

Post by MariiaI » Wed 08 May 2013 12:28

Thank you for the test project. We are investigating it and will inform you about the results as soon as possible.

Our sample project can be downloaded from http://www.devart.com/pub/Forum26948.zip

hepek
Posts: 126
Joined: Thu 07 Jul 2011 13:59

Re: column always NULL - custom column mapping

Post by hepek » Wed 08 May 2013 13:09

I figured it out.

Currently, in my partial class I have this line, and it works fine with dotConnect version 6:

Code: Select all

using System.Data.Linq.Mapping;
With version 7 I had to replace that line with:

Code: Select all

using Devart.Data.Linq.Mapping;
Custom column mapping now works with dotConnect version 7.
(*btw - this line does not work with version 6, but the first one does)

I hope my experience might help someone else with a similar issue.

thank you for your help

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: column always NULL - custom column mapping

Post by MariiaI » Mon 13 May 2013 08:54

Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.

Basically, 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.".

Post Reply