Click here to Skip to main content
15,943,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a MVC4 internet application, whose Model is using a partial class as well as a partial method. the code is as follows:
C#
namespace ePhoneBookMvc4Application.Models
{
    public partial class PhoneBook : ePhoneBookMvc4Application.Repositories.PhoneBook
    {


        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }


        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(FirstName))
            {
                yield return new RuleViolation("First Name Required", "FirstName");
            }

            if (!OnValidatePropertyForPhonebook.CharStringValidator(FirstName))
            {
                yield return new RuleViolation("Please Enter Valid First Name", "FirstName");
            }

            yield break;
        }

        
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if(!IsValid)
            {
                throw new ApplicationException("Rule violations prevent saving");
            }
        }

    }
}

but during Build, i am getting an error as follows:
VB
No defining declaration found for implementing declaration of partial method ePhoneBookMvc4Application.Models.PhoneBook.OnValidate(System.Data.Linq.ChangeAction) 


whereas the partial method is defined in the .designer.cs file in the Repositories. Is it necessary that the Repository.cs,IRepository and the Phonebook.dbml files must be in the same folder as the Model.Phonebook ?
Please help.
Posted
Updated 5-Feb-13 17:46pm
v3

1 solution

This is what it is: you did not provide matching method declaration in some partial class declaration. As you don't mention about it, I would be curious to know what was your idea about it. Partial methods are as trivial as this:
http://msdn.microsoft.com/en-us/library/6b0scde8.aspx[^].

—SA
 
Share this answer
 
Comments
scarletwitch1990 5-Feb-13 23:51pm    
actuall i have....it is defined in Repository.designer.cs
Sergey Alexandrovich Kryukov 5-Feb-13 23:57pm    
Then show it! How anyone can find your bugs if you don't show relevant code?
But better yet, just read the documentation referenced above and check up if you comply or not... the usage of partial methods is way too simple.
—SA
scarletwitch1990 6-Feb-13 0:12am    
thanks for the documentation, but i have already followed all the tips.But my declaration of the partial method is in one class in a file (eg:- a controller file) and the definition is in other file(eg:- a helper file) of the application. And when i Build my project it gives me the above error.
My question is whether it is mandatory to keep the definition and declaration in the same folder???
Sergey Alexandrovich Kryukov 6-Feb-13 0:26am    
Classes and partial declarations are not related to "folders"... and even files. Your problem is somewhere else. Do you want me to solve it not looking at our code? Come on...
—SA
Sergey Alexandrovich Kryukov 6-Feb-13 0:27am    
Excuse me! Not in one class?! What do you mean? Class or file?...
—SA

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