2

I have a viewmodel as such:

    namespace Lipton.Areas.Drugs.Models
    {
      public class DrugViewModel
      {
        public string ID { get; set; }
        public IEnumerable<tblDrug> DrugList { get; set; }
      }
    }

The above works fine. The reason why it works is because for tblDrug is in the appropriate namespace: Lipton.Areas.Drugs.Models. What happens though if I need to add an IEnumerable for another table - tblEmp which is in a totally different namespace (Lipton.Areas.Empl.Models:

    namespace Lipton.Areas.Drugs.Models
    {
      public class DrugViewModel
      {
        public string ID { get; set; }
        public IEnumerable<tblDrug> DrugList { get; set; }
        public IEnumerable<tblEmp> EmpList { get; set; }
      }
    }

How would I modify the above code to work due to the namespace issue?

4

2 に答える 2

1

using名前空間をスコープに入れるためにディレクティブを追加して、この名前空間で宣言された型を完全修飾せずに直接使用できるようにします。

namespace Lipton.Areas.Drugs.Models
{
    using Lipton.Areas.Empl.Models

    public class DrugViewModel
    {
        public string ID { get; set; }
        public IEnumerable<tblDrug> DrugList { get; set; }
        public IEnumerable<tblEmp> EmpList { get; set; }
     }
}

でタグ付けされている理由もわかりません。それは基本的なです。

于 2012-07-21T07:18:04.420 に答える
0

名前空間を明示的に追加できますtblEmp

namespace Lipton.Areas.Drugs.Models
{
  public class DrugViewModel
  {
    public string ID { get; set; }
    public IEnumerable<tblDrug> DrugList { get; set; }
    public IEnumerable<Lipton.Areas.Empl.Models.tblEmp> EmpList { get; set; }
  }
}
于 2012-07-20T22:21:13.957 に答える