Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Best practise for using EF Entities

Best practise for using EF Entities

Scheduled Pinned Locked Moved C#
csharpdatabaselinqcareer
23 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    You have to import the System.Data.Entity namespace at the top of the code file. If you get the red squiggly under Find, right click the word and then you should be able to pick Resolve -> System.Data.Entity.

    A guide to posting questions on CodeProject[^]
    Dave Kreskowiak

    S Offline
    S Offline
    Shady George
    wrote on last edited by
    #11

    I've done all of that Dave, and I still get the red squiggly. It's got to be something to do with the version of the System.data.entity dll that I'm importing. EF reports that it's using version 6, but the DLL reports version 4. I'll keep trying, but until then, I'll use the version that works, but I can't help feeling that i's going to get up and bite me one day.

    D 1 Reply Last reply
    0
    • S Shady George

      I've done all of that Dave, and I still get the red squiggly. It's got to be something to do with the version of the System.data.entity dll that I'm importing. EF reports that it's using version 6, but the DLL reports version 4. I'll keep trying, but until then, I'll use the version that works, but I can't help feeling that i's going to get up and bite me one day.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #12

      If you've got a mismatch like that, something went terribly wrong. Go to the Package Manager Console and do a Uninstall-Package EntityFramework. Then go through the References in the project and remove the EntityFramework reference if it's still there. Once that's done, you can go back to the Package Manager Console and do a Install-Package EntityFramework". That should take care of any mismatches. [A guide to posting questions on CodeProject](http://www.codeproject.com/scrapbook/ForumGuidelines.asp)[[^](http://www.codeproject.com/scrapbook/ForumGuidelines.asp "New Window")] **Dave Kreskowiak**

      S 2 Replies Last reply
      0
      • D Dave Kreskowiak

        If you've got a mismatch like that, something went terribly wrong. Go to the Package Manager Console and do a Uninstall-Package EntityFramework. Then go through the References in the project and remove the EntityFramework reference if it's still there. Once that's done, you can go back to the Package Manager Console and do a Install-Package EntityFramework". That should take care of any mismatches. [A guide to posting questions on CodeProject](http://www.codeproject.com/scrapbook/ForumGuidelines.asp)[[^](http://www.codeproject.com/scrapbook/ForumGuidelines.asp "New Window")] **Dave Kreskowiak**

        S Offline
        S Offline
        Shady George
        wrote on last edited by
        #13

        Thanks Dave, will do.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          If you've got a mismatch like that, something went terribly wrong. Go to the Package Manager Console and do a Uninstall-Package EntityFramework. Then go through the References in the project and remove the EntityFramework reference if it's still there. Once that's done, you can go back to the Package Manager Console and do a Install-Package EntityFramework". That should take care of any mismatches. [A guide to posting questions on CodeProject](http://www.codeproject.com/scrapbook/ForumGuidelines.asp)[[^](http://www.codeproject.com/scrapbook/ForumGuidelines.asp "New Window")] **Dave Kreskowiak**

          S Offline
          S Offline
          Shady George
          wrote on last edited by
          #14

          I've been battling since Tuesday to fix this Dave. (sorry for taking so much of your time), I've done what you detailed above, but still the 'find' method isn't recognised. Funny thing though, the text I get when I try to use the method is: "Error 1 'System.Data.Objects.ObjectSet' does not contain a definition for 'find' EntityResearch...." I thought the find method would be in System.Data.Entity? I've gone so far as repairing my .NET 4.5 but that didn't work either.

          D 1 Reply Last reply
          0
          • S Shady George

            I've been battling since Tuesday to fix this Dave. (sorry for taking so much of your time), I've done what you detailed above, but still the 'find' method isn't recognised. Funny thing though, the text I get when I try to use the method is: "Error 1 'System.Data.Objects.ObjectSet' does not contain a definition for 'find' EntityResearch...." I thought the find method would be in System.Data.Entity? I've gone so far as repairing my .NET 4.5 but that didn't work either.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #15

            Repairing anything isn't going to do anything for you. Nothing is broken except your code. There are multiple Find methods. The one that works on DbSets is in System.Data.Entity. If it's saying the you're using the System.Data.Objects namespace version, you're not using Entity Framework. Your entity sets have been defined using ObjectSet instead of DbSet.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            S 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Repairing anything isn't going to do anything for you. Nothing is broken except your code. There are multiple Find methods. The one that works on DbSets is in System.Data.Entity. If it's saying the you're using the System.Data.Objects namespace version, you're not using Entity Framework. Your entity sets have been defined using ObjectSet instead of DbSet.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              S Offline
              S Offline
              Shady George
              wrote on last edited by
              #16

              How can I define my entity sets using DbSet then? To all intents and purposes I am using Entity framework, it's calling it up in app.config, and in the references, so what can be going wrong?

              D 1 Reply Last reply
              0
              • S Shady George

                How can I define my entity sets using DbSet then? To all intents and purposes I am using Entity framework, it's calling it up in app.config, and in the references, so what can be going wrong?

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #17

                Using CodeFirst, in your DbContext derived class:

                public DbSet MyTableName { get; set; }
                

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Using CodeFirst, in your DbContext derived class:

                  public DbSet MyTableName { get; set; }
                  

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  S Offline
                  S Offline
                  Shady George
                  wrote on last edited by
                  #18

                  Thanks Dave, But what If I'm using DB first?

                  D 1 Reply Last reply
                  0
                  • S Shady George

                    Thanks Dave, But what If I'm using DB first?

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #19

                    Wait, you mentioned EF 4.0 .DLL's, correct? Is this an old EF 4.0 project you're upgrading?? If so, see Upgrading to EF6[^].

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    S 3 Replies Last reply
                    0
                    • D Dave Kreskowiak

                      Wait, you mentioned EF 4.0 .DLL's, correct? Is this an old EF 4.0 project you're upgrading?? If so, see Upgrading to EF6[^].

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak

                      S Offline
                      S Offline
                      Shady George
                      wrote on last edited by
                      #20

                      No, I started a new project to test the find method, before I used it in one of my operational ones. My app.config looks like this:

                      but the version of Sysytem.Data.Entity.Dll reports back as being version 4. I've downloaded a version 5 of this DLL, but even that r4ports that it's version 4.0

                      1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        Wait, you mentioned EF 4.0 .DLL's, correct? Is this an old EF 4.0 project you're upgrading?? If so, see Upgrading to EF6[^].

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak

                        S Offline
                        S Offline
                        Shady George
                        wrote on last edited by
                        #21

                        I started a new project to test the find method, and I'm still getting the problem. My app.config looks like this:

                        The System.Data.Entity DLL reports as being version 4.0. I downloaded a version 5.0 of this DLL, but even that reports as version 4.0

                        1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          Wait, you mentioned EF 4.0 .DLL's, correct? Is this an old EF 4.0 project you're upgrading?? If so, see Upgrading to EF6[^].

                          A guide to posting questions on CodeProject[^]
                          Dave Kreskowiak

                          S Offline
                          S Offline
                          Shady George
                          wrote on last edited by
                          #22

                          I've found what I've been doing wrong Dave. When I've been adding the Entity Data model when I started the project, I've been deleting the two .tt template files and setting the code generation strategy in the edmx properties to 'default'. This hasn't been generating the (correct) code to use dBSet. I've still got a lot to learn yet about this, as it's opened a few more cans of worms for me, (For example, what happened to my 'AddObject' methods?) This highlights my original point. I'm a freelance developer, and have been for about 10 years now. I work by myself, and I have no-one to bounce ideas off, or show me my mistakes. I learnt EF by buying Julia Lerman's book and studying enough of it to get my current project up and running, but not going any further. When I worked for a software house in England, I used to dread code review day, but I can see now how useful it was. I know I'm still missing a lot, and I would be grateful if you could point me to a good tutorial about the correct way to deal with Entity Framework, and .tt files and all. Thanks for all your patience Dave, it's been much appreciated. George

                          D 1 Reply Last reply
                          0
                          • S Shady George

                            I've found what I've been doing wrong Dave. When I've been adding the Entity Data model when I started the project, I've been deleting the two .tt template files and setting the code generation strategy in the edmx properties to 'default'. This hasn't been generating the (correct) code to use dBSet. I've still got a lot to learn yet about this, as it's opened a few more cans of worms for me, (For example, what happened to my 'AddObject' methods?) This highlights my original point. I'm a freelance developer, and have been for about 10 years now. I work by myself, and I have no-one to bounce ideas off, or show me my mistakes. I learnt EF by buying Julia Lerman's book and studying enough of it to get my current project up and running, but not going any further. When I worked for a software house in England, I used to dread code review day, but I can see now how useful it was. I know I'm still missing a lot, and I would be grateful if you could point me to a good tutorial about the correct way to deal with Entity Framework, and .tt files and all. Thanks for all your patience Dave, it's been much appreciated. George

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #23

                            The best out there are Julia's books. I have them all and am going the CodeFirst route on my current project. I've been working on this one for the last year and will probably be doing it for another.

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups