Resolved edmx + partial class

Andy75

Member
Joined
May 29, 2020
Messages
18
Programming Experience
1-3
Hi all,
I am trying to extend my edmx with partial classes (database first in c# with visual studio 2019).

In visual studio 2010 I put edmx and partial classes in the same directory.
Then in my partial class I wrote

C#:
 public partial class Product
    {
        private dbEntities ctx;
       
        public Product()
        {
            ctx = new dbEntities(ConfigurationManager.ConnectionStrings["dbEntities"].ConnectionString);
        }

        ~Product()
        {
            ctx = null;
        }

        public Product LoadOne(int id)
        {
                return
                    (from rec in ctx.Product
                    where rec.IdProduct.Equals(id)
                    select rec).FirstOrDefault();
        }
   
         //....... another method
   
    }




Now with VS2019 it no longer works, it tells me that the Product class already exists.
In fact it exists, inside the edmx. So I moved my partial classes into a new directory, but it doesn't work.

I tried to rename my classes like Product.partial.cs, but it can't find the string to access.

It was so comfortable to work as before, does anyone suggest anything?

Thanks
A.
 
Solution
You need to distinguish between the class name and the file name. If you have the code files for both partial class definitions in the same folder then obviously the file names must be different. "SomeType.partial.cs" isn't a great name because both class definitions are partial, but that's not the need of the world. Regardless of where the code files are, the partial class declarations must be in the same namespace and they must all have the partial keyword in them.
You need to distinguish between the class name and the file name. If you have the code files for both partial class definitions in the same folder then obviously the file names must be different. "SomeType.partial.cs" isn't a great name because both class definitions are partial, but that's not the need of the world. Regardless of where the code files are, the partial class declarations must be in the same namespace and they must all have the partial keyword in them.
 
Solution
Back
Top Bottom