Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all,
I have Repository contains :
C#
public T Single(Func<T, bool> exp)
     {
         return GetTable.SingleOrDefault(exp);
     }

Linq contain tables: City
I want to create a partial class and add more property in it. I have created in DAL.BO
C#
public partial class City : DAL.City
{
      public string StateName
      {
          get
          {
              return this.StateZipCode.Name;
          }
      }
}


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 ?
Posted
Updated 28-Oct-14 6:44am
v2
Comments
Sergey Alexandrovich Kryukov 28-Oct-14 13:02pm    
Partial classes is just a syntax candy (very good one); they are unrelated to the problem.
You did not show DAL.BO.City in your code sample, and did not show all namespaces involved.
The question does not makes much sense. Just use VS's "Go to definition" and see what is where, then fix it.
—SA

1 solution

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:
C#
class DAL
{
    //properties and methods
    partial class BO
    {
        //properties and methods
    
        partial class City
        {
            //properties and methods
        }
    }
}

It should give you: DAL.BO.City
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-Oct-14 15:55pm    
Yes.
Or, it could be
namespace DAL.BO;
partial class City {/* ... */}


The actual problem is having two different classes instead of one. It gives me the idea: probably OP thought that some two class parts (in the sense of partial definitions) merge into one type, but in fact, it appeared to be two different types, due to some mess in namespaces/nesting.

—SA
Maciej Los 28-Oct-14 16:02pm    
It could be. Let's see ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900