0

I've got an EDMX diagram generated from a SQL Server database. It generates a partial class like the following:-

public partial class Profile
{
    public Profile()
    {
        // Constructor Info here
    }

    // Various string/int/bit properties
    public virtual ICollection<ProfileImage> ProfileImages { get; set; }
}

The ICollection at the bottom is a sub table linked via the Primary Key from Profile. In this table is a string with an image file name for the profile.

I wanted to be able to add an addition property to this class to pre-pend a folder structure before the file name, and I tried the following, but I get a compile error:-

public partial class Profile
{
    public string ImageFileName { get; set; }
    public string ProfileImageURL
    {
        get
        {
            return "~/images/folder/folder/" + this.ImageFileName;
        }
    }
}

The error is fairly obvious: Profile is ambiguous between 'XXX' and 'YYY'. But they are two partial classes, and I thought this could work? How do I amend this to add my own properties onto a DB generated class from the EDMX?

Thanks in advance!

Mike Upjohn
  • 1,251
  • 2
  • 16
  • 38
  • 1
    HI ..to extend something FRom EDMX i suggest to you to use partial class in another file – federico scamuzzi Jan 18 '17 at 12:07
  • Thanks guys. Yes duplicate, didn't realise the namespace was the issue here. I understood it that you could have two partial classes with the same name across the project, not just the namespace. – Mike Upjohn Jan 18 '17 at 12:16

2 Answers2

1

The two partial classes should have the same namespace

user45
  • 105
  • 2
  • 9
0

So I've found that given the original partial class is generated, creating another partial class with my own properties in, will work as long as the second partial class has the same namespace as @Hanna Haddad said.

namespace MyProject.Models
{
    public partial class Profile
    {
        public string ProfileImageURL
        {
            get
            {
                return "~/images/folder/folder/" + this.ImageFileName;
            }
        }
    }
}

Thanks everyone for your input!

Mike Upjohn
  • 1,251
  • 2
  • 16
  • 38