Click here to Skip to main content
Rate this: bad
good
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)
        {
            if(!IsValid)
            {
                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
v3

1 solution

Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/6b0scde8.aspx[^].
 
—SA
  Permalink  
Comments
sarahnimy at 5-Feb-13 23:51pm
   
actuall i have....it 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.
—SA
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...
—SA
Sergey Alexandrovich Kryukov at 6-Feb-13 0:27am
   
Excuse me! Not in one class?! What do you mean? Class or file?...
—SA
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...
—SA
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...
—SA
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?
 
—SA
sarahnimy at 6-Feb-13 2:26am
   
yep
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 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
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