dcsimg
Results 1 to 12 of 12

Thread: Problem with entity passed as argument

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Problem with entity passed as argument

    Hello !
    I have this code :
    Code:
    Public Class myclass
        ....
        Private cont As MyentEntities
        .....
        .....
    
        Public Sub New( ByRef cnx As MyentEntities)
           .....
            cont = cnx
            .....
        End Sub
    
    Public Sub test
    .....
    
    If cont.mytable1.Count=1 then
    
    .....
    end if 
    
    End Sub
    End class
    
    
    'On my main form :
    
    .......
    Dim E1 as MyEntEntities
    Dim m1 as myclass
    Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load 
    
    E1=New MyentEntities
    m1=new MyClass(E1)
    ........
    
    End Sub
    
    Private sub fill_entity
    
    E1.MyTable1.Tolist
    ....
    End sub
    
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    
    m1.test
    
    End Sub
    When I click the button , I get an error :

    ....the entity of type 'MyTable1' does not exist in the context.


    What's wrong ?

    Thank you

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem with entity passed as argument

    Show a screenshot of the problem in visual studio, I'd be be better able to see what is going on.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Re: Problem with entity passed as argument

    Hello !
    I can't because is a huge code. I have extracted only the code that it's related to the problem.
    Thank you !

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Problem with entity passed as argument

    What happens if you setup a breakpoint on the line that gives you the error?

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Re: Problem with entity passed as argument

    What do you mean ?
    The execution is stopped , and if I continue I get the error.

  6. #6
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem with entity passed as argument

    Then that's where your error is occurring, show a screenshot of that breakpoint and it's content on the Locals view because to be honest, I personally don't have time to load up VS just to paste this code to find out why it's not working.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Re: Problem with entity passed as argument

    There's no need to write it in your VS , just look at the logic , because there are few instructions.

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Problem with entity passed as argument

    Quote Originally Posted by mysybet123 View Post
    What do you mean ?
    The execution is stopped , and if I continue I get the error.
    You need to properly debug your application. Whenever the program enters into break mode, watch the 'MyTable1' variable to see what could be causing the error.

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Re: Problem with entity passed as argument

    Into break mode , MyTable1 is nothing , doesn't exist.

  10. #10
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Problem with entity passed as argument

    Quote Originally Posted by mysybet123 View Post
    There's no need to write it in your VS , just look at the logic , because there are few instructions.
    Okay, applying what you just said. Why don't you look at the "logic" of the code and tell me why your program is not working? If you could do that you wouldn't of posted this thread. Thing is, when you're dealing with Classes/Objects, there is so many places where something could go wrong, it's not always straight forward. You also said you had lots of code, so how do you know the problem is not coming from there, but since you don't want to show no screenshots which contains syntax highlighting then I can't offer you my help.

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Problem with entity passed as argument

    Quote Originally Posted by mysybet123 View Post
    Into break mode , MyTable1 is nothing , doesn't exist.
    Then that is why you're receiving the error. How are you expecting to access MyTable1, as in is it a property within that class?

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    48

    Re: Problem with entity passed as argument

    The problem it's this instruction inside the sub :

    Code:
    Public Sub test
    .....
    If cont.mytable1.Count=1 then
    .....
    end if
    and the problem is that this sub is inside the class.
    I made a test and create a similar sub outside the class ( of course with E1 entity ) , and it's working perfectly
    So the problem is that the entity E1 passed as argument in the class New's sub , doesn't "know" the changes that are made outside with E1.

    So I think this is the problem with the way this argument is working.
    Maybe someone that know better in theory can help me to find what I'm wrong.
    Thank you !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width