与linq的partical类 [英] Partical class with linq

查看:82
本文介绍了与linq的partical类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有Repository包含:

Hi all,
I have Repository contains :

public T Single(Func<T, bool> exp)
     {
         return GetTable.SingleOrDefault(exp);
     }



Linq包含表格:City

我想创建一个分部类并在其中添加更多属性。我在DAL.BO中创建了


Linq contain tables: City
I want to create a partial class and add more property in it. I have created in DAL.BO

public partial class City : DAL.City
{
      public string StateName
      {
          get
          {
              return this.StateZipCode.Name;
          }
      }
}





一切似乎都不错,但在代码中,当我想找到City时:

DAL.BO.City city = unitOfWork.CityRepository.Single(a => a.CityID == Convert.ToInt16(empid));

它无法从 DAL.City 转换为 DAL.BO.City

我知道这个问题。

我现在该怎么办?



Everything seems OK, but in code, when I want find City:
DAL.BO.City city = unitOfWork.CityRepository.Single(a => a.CityID == Convert.ToInt16(empid));.
It can not convert from DAL.City to DAL.BO.City.
I know that problem.
How can I do now ?

推荐答案

请阅读谢尔盖对他提问的评论。正如他所提到的,课堂宣言是错误的。



请阅读:部分类和方法(C#编程指南) [ ^ ]。

看起来你想要创建嵌套类 [ ^ ]((推荐) [ ^ ]。



正确的定义是:

Please, read Sergey's comment to he question. As he mentioned, the declaration of class is wrong.

Please, read this: Partial Classes and Methods (C# Programming Guide)[^].
It looks like you want to create nested classes[^] ((recommendations)[^].

The proper definition is:
class DAL
{
    //properties and methods
    partial class BO
    {
        //properties and methods
    
        partial class City
        {
            //properties and methods
        }
    }
}



它应该给你: DAL.BO.City


这篇关于与linq的partical类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆