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. EF Code-First to Existing Database

EF Code-First to Existing Database

Scheduled Pinned Locked Moved C#
questioncsharpdatabase
2 Posts 2 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.
  • J Offline
    J Offline
    jasonalien
    wrote on last edited by
    #1

    Hello all, I have applied EF Code-First to Existing Database like this : 1- Created an ADO.NET Entity Data Model 2- Chose Code First from Database All of the classes generated correctly, except there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? Another question is, how can I be sure that EF kept the one-to-many or many-to-many relationships? There is nothing like :

    public virtual ICollection Posts { get; set; }

    Thanks in advance.

    M 1 Reply Last reply
    0
    • J jasonalien

      Hello all, I have applied EF Code-First to Existing Database like this : 1- Created an ADO.NET Entity Data Model 2- Chose Code First from Database All of the classes generated correctly, except there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? Another question is, how can I be sure that EF kept the one-to-many or many-to-many relationships? There is nothing like :

      public virtual ICollection Posts { get; set; }

      Thanks in advance.

      M Offline
      M Offline
      Maciej Los
      wrote on last edited by
      #2

      (...) there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones? No. You sohuldn't change anything unless you're really shure what you're doing. Please, see: Working with Entity Keys[^] Entity Framework (EF) Documentation[^] An .edmx file[^] Data Points: Code First Goodies in Entity Framework 6[^]

      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