Entity Framework Code-First Migrations: Listing 1

DataBaseStruct.vb

Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations

'*** Note: This is the "DataAccess" Namespace ***

#Region "Table Classes"
'************************************************************************************************
'Classes describing individual table structure for each table identified in the context database
'************************************************************************************************

<Table("VehicleTable")>
Public Class Vehicle
Public Property VehicleId() As Int32
<Column("MakeOfCar")>
Public Property Make() As String
Public Property Model() As String
Public Property VehicleType() As VehicleType
Public Property VIN() As String            'New Property Added
Public Property LicensePlate() As String   'New Property Added
End Class

Public Class VehicleType
Public Property VehicleTypeId() As Int32
Public Property Name() As String
Public Property Description() As String
Public Property NumberOfAxles As Int32     'New Property Added
End Class

#End Region

#Region "Context Class"
'*******************************************************
'Context class describing Database and its tables
'*******************************************************
Public Class TransportationDB
Inherits DbContext

Public Property Vehicles() As DbSet(Of Vehicle)
Public Property VehicleTypes() As DbSet(Of VehicleType)

End Class

#End Region

About the Author

Sam Nasr has been a software developer since 1995, focusing mostly on Microsoft technologies. Having achieved multiple certifications from Microsoft (MCAD, MCTS(MOSS), and MCT), Sam develops, teaches, and tours the country to present various topics in .Net Framework. He is also actively involved with the Cleveland C#/VB.Net User Group, where he has been the group leader since 2003. In addition, he also started the Cleveland WPF Users Group in June 2009, and the Cleveland .Net Study Group in August 2009, and is the INETA mentor for Ohio. When not coding, Sam loves spending time with his family and friends or volunteering at his local church. He can be reached by email at [email protected].

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube