Click here to Skip to main content
Rate this: bad
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 18:43pm
Edited 5-Feb-13 18: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 at 5-Feb-13 23:51pm
actuall i is defined in Repository.designer.cs
Sergey Alexandrovich Kryukov at 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.
sarahnimy at 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 at 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...
Sergey Alexandrovich Kryukov at 6-Feb-13 0:27am
Excuse me! Not in one class?! What do you mean? Class or file?...
sarahnimy at 6-Feb-13 0:45am
im sorry i meant folders not files
Sergey Alexandrovich Kryukov at 6-Feb-13 1:51am
As I say, it does not matter...
sarahnimy at 6-Feb-13 0:33am
what part of the code do you want me to post??
Sergey Alexandrovich Kryukov at 6-Feb-13 1:53am
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...
Sergey Alexandrovich Kryukov at 6-Feb-13 1:54am
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 at 6-Feb-13 2:26am
sarahnimy at 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
0 Sergey Alexandrovich Kryukov 464
1 OriginalGriff 449
2 Maciej Los 295
3 Peter Leow 250
4 CPallini 180
0 Sergey Alexandrovich Kryukov 6,971
1 OriginalGriff 5,532
2 Peter Leow 3,997
3 Mika Wendelius 2,850
4 CHill60 2,808

Advertise | Privacy | Mobile
Web03 | 2.8.150224.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
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