Araz
Araz

Reputation: 190

partial class is not accessible anymore from the other partial class using Visual 2013 .net C#

I am using .net 4.5.50938 Visual Studio Community 2013 V12.0.31101.00 Update 4 OS: Win 7 I am trying to copy my existing website from VS2012 to a project/solution in VS2013


Using Visual studio I have an Entity Model from database created in place in my 'Models' folder which has partial 'EntityClass1' class as one of its classes. Now I go to the 'App_Code' folder and I add a class named 'EntityClass1' and I add the same namespace as 'EntityClass1' uses with the key words. But unlike Visual studio 2012 I cannot access EntityClass1's properties!

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace MyProjectToVs2013.Models
{
    using System;
    using System.Collections.Generic;

    public partial class EntityClass1
    {
        public System.Guid ID { get; set; }
        public string Title { get; set; }
        public System.Guid Class1ID { get; set; }

        public virtual Entity34 Entity34 { get; set; }
    }
}

and in the other EntityClass1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyProjectToVs2013.Models;
using System.ComponentModel.DataAnnotations;

namespace MyProjectToVs2013.Models
{
    public partial class EntityClass1
    {
        public EntityClass1()
        { 
            //TODO: Add constructor logic here
        }  

        public void createEntityClass1()
        {
//here I am trying to access the properties and unlike VS2012
 I cannot!! there is no such properties available via intelliSense: 
        Title // not appearing!
        }

    }


}

Upvotes: 3

Views: 3516

Answers (2)

Araz
Araz

Reputation: 190

I needed to go to the EntityClass1 file both in the App_Code and in Model folder and set the properties called 'NameSpace' for both files to the "MyProjectToVs2013.Models" and rebuild the project. now it works :)

Source: http://dzapart.blogspot.com.tr/2011/11/creating-common-partial-class-with.html

Upvotes: 4

Licht
Licht

Reputation: 1109

You've placed your method outside the class definition so no members will be available.

Try this:

public partial class EntityClass1
{
    public EntityClass1()
    { 
        //TODO: Add constructor logic here
    }

    public void createEntityClass1()
    {
        Title = "anything";
    }

}

Upvotes: 0

Related Questions