How to create a custom property not mapped to table column

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
genesplitter
Posts: 10
Joined: Sat 08 Aug 2009 00:08

How to create a custom property not mapped to table column

Post by genesplitter » Fri 12 Mar 2010 20:00

In previous LINQ projects I often manually add new properties to existing auto-generated LINQ classes, using the magic of partial classes. These are straight Microsoft LINQ / SQL Server projects and I did *not* include an attribute for these properties. When I tried the same with my devart/Oracle LINQ project I got the following error:

Cannot find metainformation for property User.MyManuallyAddedProperty. Please check that the property is mapped to the table column.

It appears my new property must have an attribute set, so I included an attribute even though this property is not mapped to any database column:

[Column(Name = @"MyManuallyAddedProperty")]

I expected to get an oracle error:

ORA-00904: "T2"."MYMANUALLYADDEDPROPERTY": invalid identifier

I then changed the property attribute to:

[Column(IsDbGenerated = false)]

Which I hoped would indicate no database access, but yet another oracle error was thrown on runtime.

My question is how to I add a property that is *not* mapped to a column in the database?

Thank you,

Donald Lee-
Dept. of Energy - National Science Research Center
dotConnect for Oracle 5.60 Beta

*** Example partial class code *******************************

// This file is intended to be edited manually

public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
{
[Column(IsDbGenerated = false)] //error thrown if no attribute!
public string MyManuallyAddedProperty
{
get { return "hello"}
}
}

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 16 Mar 2010 12:12

Why don't you use the DataContext.cs file?
It is intended for customization code.
Here is a simple sample code:

Code: Select all

namespace DataContext1 {
  partial class DataContext1 {

    // Place your implementation of partial extension methods here
  }
  public partial class Dept {
    private string field;
    public string Field {
      get {
        return field;
      }
      set {
        field = value;
      }
    }
  }
}

genesplitter
Posts: 10
Joined: Sat 08 Aug 2009 00:08

Post by genesplitter » Tue 16 Mar 2010 18:02

Yep, that's where the code should go (and is). Still not sure what my problem is.

// This file is intended to be edited manually

using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;

namespace ProposalDataContext
{
partial class ProposalDataContext
{

// Place your implementation of partial extension methods here
}
public partial class ProposalProjectUser
{
public string WorkLocation
{
get { return "hello"; }
}
}
}

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 17 Mar 2010 09:06

What dotConnect version are you using?

Post Reply