question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use Virtual/Override properties to override column name

See original GitHub issue

Hi!

I’m trying to use override for properties but it doesn’t take it’s attributes. Is it supported?

public class BaseClass
{
        [Column("Text base")]
        public virtual string Text { get; set; }
}

public class ClildClass : BaseClass
{
        [Column("Text new")]
        public override string Text { get; set; }
}

public class Build
{
        public BaseClass BuildNew()
        {
                return new ClildClass(); 
        }
}

In the end I want to see ‘Text new’ but keep getting ‘Text base’

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mgansscommented, May 24, 2022

IMHO the design creating an additional class is cleaner from an object-oriented POV (you could even make the base class abstract).

I’ve added the Inherit property in 5.2.405. Your original code would now become:

public class BaseClass
{
    [Column("Text base", Inherit = false)]
    public virtual string Text { get; set; }
}

public class ChildClass : BaseClass
{
    [Column("Text new")]
    public override string Text { get; set; }
}
1reaction
jake8787commented, May 19, 2022

Fixed in 5.2.404.

Awesome 😃 Enjoying your library!

Somehow managed to find a workaround though

mapper => mapper.Ignore<BaseClass>(x => x.Text),
mapper => mapper.AddMapping<BaseClass>("Text new", x => x.Text)
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Overriding fields or properties in subclasses
Use an abstract Property and override it on the inherited classes. This benefits from being enforced (you have to override it) and it...
Read more >
Override a virtual function
In Class View, select the class. · In the Properties window, select the Overrides button. · If the function has no override, then...
Read more >
Understanding virtual, override and new keyword in C#
Virtual and Override keyword are used for method overriding and new keyword is used for method hiding.
Read more >
Why was C# made with "new" and "virtual+override ...
C# forces one to use virtual and new/override to consciously make those decisions. There are several reasons. One is performance.
Read more >
Can I override properties of business objects?
Overridden properties use the same column and cannot modify their parameters. So, there is no point in applying attributes from the DevExpress.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found