Click here to Skip to main content
13,048,805 members (70,595 online)
Rate this:
Please Sign up or sign in to 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:
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)
                throw new ApplicationException("Rule violations prevent saving");

but during Build, i am getting an error as follows:
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 5-Feb-13 17:43pm
Updated 5-Feb-13 17:46pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^].

sarahnimy 5-Feb-13 23:51pm
actuall i is defined in Repository.designer.cs
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.
sarahnimy 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???
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...
Excuse me! Not in one class?! What do you mean? Class or file?...
sarahnimy 6-Feb-13 0:45am
im sorry i meant folders not files
As I say, it does not matter...
sarahnimy 6-Feb-13 0:33am
what part of the code do you want me to post??
You should know better. Excuse me, you want, not me... You should show relevant parts, apparently. If you have anything partial, at least show all the parts...

And, to be serious, it's the best to develop a separate code sample specially for asking a question, of minimally possible size, make sure it reproduces the problem...
You should have in some part of the same class:

partial void OnValidate(System.Data.Linq.ChangeAction action);

Do you have it? In the same class, are you sure?

sarahnimy 6-Feb-13 2:26am
sarahnimy 6-Feb-13 0:35am
i used the NerdDinner example of MVC to create another application for a phone book.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100