【问题标题】:How to access data of a domain class in another model class?如何访问另一个模型类中的域类的数据?
【发布时间】:2020-03-19 08:11:24
【问题描述】:

我有一个这样的域类,

public class DomainClassExample
{
        public int ClientAssessmentId { get; set; }

        public int IfaId { get; set; }
}

我想在另一个模型类中获取这个域类中的数据作为列表。 有什么办法可以做到这一点?

【问题讨论】:

  • @DaggeJ 我试过了,但它得到了空值。

标签: c# asp.net entity-framework model-view-controller


【解决方案1】:

您可以将模型作为属性添加到任何其他类。

public class AnotherModelClassExample
{
    //...other properties

    public IEnumerable<DomainClassExample> DomainClassExampleList { get; set; }

   public AnotherModelClassExample(){
     DomainClassExampleList  = dbcontext.DomainClassExamples.ToList();
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 2014-01-18
    • 2013-06-12
    • 2014-11-18
    • 1970-01-01
    相关资源
    最近更新 更多