Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:36:38+00:00 2026-06-15T19:36:38+00:00

ActionBase, ActionA, ActionB and ActionC are Entities (from a database). ActionA, ActionB and ActionC

  • 0

ActionBase, ActionA, ActionB and ActionC are Entities (from a database). ActionA, ActionB and ActionC are derived type of ActionBase.

ActionB and ActionC implements ISpecialAction with a SpecialProperty.

ex :

public interface ISpecialAction
{
    Guid SpecialProperty { get; }
}

public partial class ActionBase
{
    public objectX OnePropertyBase { get; set; }
}

public partial class ActionA : ActionBase
{
    public objectY OnePropertyA { get; set; }
}

public partial class ActionB:ActionBase,ISpecialAction 
{
    public objectZ OnePropertyB { get; set; }

    public Guid SpecialProperty
    {
        get
        {
            return OnePropertyB.ID;
        }
    }
}

public partial class ActionC : ActionBase ,ISpecialAction 
{
    public objectW OnePropertyC { get; set; }

    public Guid SpecialProperty
    {
        get
        {
            return OnePropertyC.ID;
        }
    }
}

My problem is that SpecialProperty is build from other Properties of the objects (ActionB or ActionC) and when the cast (to ISpecialAction) is done, OtherProperty and OtherProperty2 are null.
I tried :

GetActionBase().ToList().Where(x=>x is ISpecialAction && ((dynamic) x).SpecialProperty== p_SpecialProperty);
GetActionBase().ToList().Where(x=>x is ISpecialAction && ((ISpecialAction) x).SpecialProperty== p_SpecialProperty);
GetActionBase().ToList().OfType<ISpecialAction>().Where(x => x.SpecialProperty== p_SpecialProperty).Cast<ActionBase>();
return GetActionOnGoing().ToList().OfType<ICityAction>().Cast<ActionBase>().Where(x => ((dynamic)x).CityId == p_CityId);

remark : OfType<> doesn’t works with an Interface in Linq to entities but is ok in Linq to object

How do I access my property interface without knowing the type of the object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:36:39+00:00Added an answer on June 15, 2026 at 7:36 pm

    I might missed something but this is Ok with the code you provided :

    public class objectX
    {
    
    }
    public class objectY
    {
    
    }
    public class objectZ
    {
        public Guid ID { get { return Guid.NewGuid();} }
    }
    public class objectW
    {
        public Guid ID { get { return new Guid(); } }
    }
    
    class Program
    {
        private static Guid p_SpecialProperty;
        static void Main(string[] args)
        {
            var result = GetActionBase().ToList().Where(x => x is ISpecialAction && ((dynamic)x).SpecialProperty == p_SpecialProperty).FirstOrDefault();
            var result1 = GetActionBase().ToList().Where(x => x is ISpecialAction && ((ISpecialAction)x).SpecialProperty == p_SpecialProperty).FirstOrDefault();
            var result2 = GetActionBase().ToList().OfType<ISpecialAction>().Where(x => x.SpecialProperty == p_SpecialProperty).Cast<ActionBase>().FirstOrDefault();
                    }
    
        private static IEnumerable<ActionBase> GetActionBase()
        {
            return new List<ActionBase> {new ActionA{OnePropertyA= new objectY()}, new ActionB{OnePropertyB=new objectZ()},new ActionC{OnePropertyC=new objectW()} };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<action name=actionA class=com.company.Someaction> <result name=success type=redirect-action> <param name=actionName>OtherActionparam> <param name=paramA>${someParams}</param> <param name=paramB>${someParams}</param> <param name=aBoatLoadOfOtherParams>${aBoatLoadOfOtherParams}</param>
Suppose I have defined route like that, context.MapRoute( Preview, /preview/{id}/{type}, new { controller =
I've seen a few examples of people using this syntax for HTML.BeginForm: (Html.BeginForm<Type>(action =>
I understand why calling a virtual function from a constructor is bad, but I'm
I want to redirect from an action in one controller to an action in
What is the best way of comparing that my image saved to a database
See the following code: public abstract class Base { public virtual void Foo<T>() where
I'm attempting to unit test some code using NUnit. I have a method: public
I'm trying to make a design for some sort of IExecutable interface. I will
Is there a way to make the parameters of this extension method 'intellisensible' from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.