Giter Site home page Giter Site logo

microsoftdocs / ef-core-for-beginners Goto Github PK

View Code? Open in Web Editor NEW
83.0 9.0 55.0 1.52 MB

Project for Entity Framework Core for Beginners video series

License: Creative Commons Attribution 4.0 International

Dockerfile 2.01% Shell 3.91% C# 53.23% HTML 35.96% CSS 4.07% JavaScript 0.84%

ef-core-for-beginners's Introduction

languages products page_type name urlFragment description
csharp
dotnet
ef-core
sample
Code and notes for Entity Framework Core for Beginners video series
ef-core-for-beginners
All the notes and code samples to follow along with the Entity Framework Core for Beginners video series.

Entity Framework Core for Beginners video series

Hi, friend! ๐Ÿ‘‹ You've found the code and other materials to accompany the Entity Framework Core for Beginners video series. We hope you'll find it enjoyable and informative. ๐Ÿ’œ

Repository structure

The starter project for each video is located in the corresponding folder under the parts folder. For example, the starter project for Getting Started with Entity Framework Core (Part 1 of 5) is located in parts/1-getting-started.

The script, code snippets, and connection strings used for each video are located in the notes folder, organized by parts. For example, the notes for Part 1 are located in notes/1-getting-started.

Requirements

If you want to code along with the videos, we strongly recommend you first watch the supplemental video, How to code along with these videos.

The courseware was designed to be followed in one of three scenarios:

Windows with Visual Studio

This is the scenario featured in the video. This scenario requires:

  1. Clone the repository.
  2. Install the ContosoPizza database in your LocalDB instance. Use a tool like Azure Data Studio or SQL Server Management Studio.
  3. For each video (parts 1-5), open the desired project file in Visual Studio. Follow along in the videos.

Windows/macOS/Linux with .NET CLI and Visual Studio Code

This scenario uses open source tooling and supports any operating system. This scenario requires:

You are responsible for determining your own connection information for all of the above.

  1. Clone the repository.
  2. Install the ContosoPizza database on an accessible SQL Server instance. Use a tool like Azure Data Studio or SQL Server Management Studio.
  3. Open the entire repository folder in Visual Studio Code.
  4. Review the recommended extensions and install them.
  5. When everything is done loading, find the CodeTour for the video you're watching in the CODETOUR pane in the EXPLORER in VS Code. Right-click on the CodeTour and select Start Tour to begin the walkthrough. The walkthrough is in English and follows the videos step-by-step (with additional information and links).

Animation showing the launching of the first CodeTour

Windows/macOS/Linux with Docker/containers and Visual Studio Code

This scenario uses open source tooling and supports any operating system. The development container includes ALL prerequisties, including SQL Server, PostgreSQL, .NET SDK, and more. The ContosoPizza SQL Server database is also pre-configured. This is the recommended scenario.

This scenario requires:

  1. Clone the repository.
  2. Open Visual Studio Code without opening a folder.
  3. Press Ctrl+Shift+P to open the command palette. Search for and select Remote Containers-Open Folder in Container.... Select the entire repository folder.
  4. When everything is done loading, find the CodeTour for the video you're watching in the CODETOUR pane in the EXPLORER in VS Code. Right-click on the CodeTour and select Start Tour to begin the walkthrough. The walkthrough is in English and follows the videos step-by-step (with additional information and links). See the animation above to see an example of launching a CodeTour.

Alternatively, this scenario can be completed in-browser with no local tools using GitHub Codespaces.

  1. Just navigate to the repository, select Code, and create a new Codespace using the main branch.
  2. When everything is done loading, locate the CodeTour pane in the explorer, find the CodeTour for the video you're watching, and launch as described above.

Animation showing the launching of the CodeSpace on GitHub

Relevant links

Video series courseware repository

Part 1

Part 2

Part 3

Part 4

Part 5

Supplemental Video

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Legal Notices

Microsoft and any contributors grant you a license to the Microsoft documentation and other content in this repository under the Creative Commons Attribution 4.0 International Public License, see the LICENSE file, and grant you a license to any code in the repository under the MIT License, see the LICENSE-CODE file.

Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.

Privacy information can be found at https://privacy.microsoft.com/en-us/

Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise.

ef-core-for-beginners's People

Contributors

camsoper avatar gewarren avatar jongalloway avatar microsoft-github-operations[bot] avatar microsoftopensource avatar snailedlt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ef-core-for-beginners's Issues

Code Tour 1 / Step 40 - Insert Code selection points are wrong

When I insert the code on Step 40, it overwrites the using statements rather than the data operation. I think it's supposed to replace this:

var veggieSpecial = context.Products
                       .Where(p => p.Name == "Veggie Special Pizza")
                       .FirstOrDefault();

if (veggieSpecial is Product)
{
    context.Remove(veggieSpecial);
}

I think these are the values that need to be updated:

image

[BUG] part 2 ContosoPizza database is missing from docker container

image
The ContosoPizza database is missing from the docker container in part 2, resulting in anerror when trying to make a scaffold. Full log below.

vscode โžœ /workspace/parts/2-existing-databases/ContosoPizza (main) $ dotnet ef dbcontext scaffold "Data Source=localhost;Database=ContosoPizza;Integrated Security=false;User ID=sa;Password=P@ssw0rd;" Microsoft.EntityFrameworkCore.SqlServer --context-dir Data --output-dir Models
Build started...
Build succeeded.
To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "ContosoPizza" requested by the login. The login failed.
Login failed for user 'sa'.
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluarlize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:cd92aa59-5d29-4533-8b85-bd3b60b49943
Error Number:4060,State:1,Class:11
Cannot open database "ContosoPizza" requested by the login. The login failed.
Login failed for user 'sa'.

Code Tour Suggestion: Use shell command for dotnet commands

I'm not sure this is a good idea, but if it works it would be nice to use the shell command syntax to allow executing the dotnet add package ... commands in the terminal rather than requiring the user to copy and paste them. This is kind of grunt work from the learner's perspective, it doesn't teach me EF concepts.

One possible downside is that the Code Tour docs says that this creates a new terminal window and executes the steps. This might not work well in the case where we're executing several commands, or could be confusing since we're already having them type some commands in a terminal window. But... if it does work well, I think it would be a better experience.

78858896-91912600-79e2-11ea-8002-196c12273ebc 1

Desginer Nugget

  • we are asked to download the designer tool as a nugget, but it is never used .
    I suggest to add another Video to the series around the "Design First" approach , if its applicable to EF -Core users , as many are coming to this technology from a Designer approach on Entity Framework 5

Scaffolding

Dependent on a reader adding pages with entity framework core there is a chance of the tooling to fail with.

There was an error running the selected code generator: Package restore failed. Rolling back package changes

I'm sure those who created this realize that it's possible for the NuGet packages for tooling need to be updated as that is what I had to do.

Anyways the above happened to me when creating missing pages for orders but is good after updating the NuGet packages.

  • Microsoft.EntityFrameworkCore.Design Version 6.0.9
  • Microsoft.EntityFrameworkCore.Tools Version 6.0.9
  • Microsoft.VisualStudio.Web.CodeGeneration.Design Version 6.0.9

And sure that others may not run into this issue.

Code Tour steps ending with a code block display "Insert Code"

Code Tour steps that end with a code will automatically get an "Insert Code" link at the bottom. When I was walking through, I got used to always clicking the Insert Code link when prompted, which results in adding the console output sample to the cs code.

image

[BUG]: Line Endings should be LF for installSQLtools.sh

When trying to open the repo in vscode through the Dev Container: Open Folder in Container... command, I received an error. Turned out the way to fix the error was to change the line endings of the file (thanks ChatGPT!), which could be done in VSCode by clicking on the CRLF symbol in the bottom right corner and selecting LF instead of CRLF. I'm not sure if this data can be saved in the repo or not, but if it can, it could potensially save others from hours of troubleshooting:
image
image
image

ChatGPT conversation showing the error and ChatGPT's answers:
https://sharegpt.com/c/Eb5jO4b

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.