Code - github.com/CuriousDrive/BookStores Thanks for watching, please share with your friends :)
@DaniLearnsIT Жыл бұрын
You have the video I have been looking for months! Thank you dude! You are a great teacher :)
@takecare26894 жыл бұрын
You are doing a great job, thank you very very much. I didn't find these tutorials anywhere properly like that.
@CuriousDrive4 жыл бұрын
Thanks for the kind words. Please subscribe and share with your friends.
@CAPS_AMERICA2 жыл бұрын
Very good tutorial, very well-explained in details! keep making them up please!
@CuriousDrive2 жыл бұрын
Thanks for watching Brad. Please share the love!!!
@Crealnv2 жыл бұрын
I just learned about asp.net core before I learned about vb.net. I had an error when the connection name in appsettings.json was not the same as in the tutorial, but using the -force command you don't have to bother rebuilding the Entity Framework. Thank you sir
@MrPramit0074 жыл бұрын
You're my LifeSaver bro. Keep up the good work.
@CuriousDrive4 жыл бұрын
Thanks for watching Pramit. Please share with your friends too :)
@MrPramit0074 жыл бұрын
@@CuriousDrive will do 🌟
@mauriciomontoya7024 жыл бұрын
Hello, really thank u for these tutorials, it is an amazing work, you explain really good, and very useful things, keep your videos as these please, simple!!
@CuriousDrive4 жыл бұрын
Thanks for watching Mairicio and a lovely feedback. Please share with your friends it really helps the channel :)
@mauriciomontoya7024 жыл бұрын
@@CuriousDrive It will be a pleasure to share them
@thedevlife4 жыл бұрын
This video was very valuable. Thank you.
@CuriousDrive4 жыл бұрын
Thanks for watching. I am glad that you are finding them useful
@beautifulcultures12104 жыл бұрын
This exception occur when running -> was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application
@CuriousDrive4 жыл бұрын
Hmmm... weird do you think you can share your code. Maybe I will take look at it
@beautifulcultures12104 жыл бұрын
@@CuriousDrive In appsettings.json "ConnectionStrings": { "BookStoreDb": "Server=COM-LAP-451\\SQLEXPRESS;Database=BookStoreDb;Integrated Security=True" } Package Manager Console PM> Scaffold-DbContext -Connection Name=BookStoreDb Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force Build started... Build succeeded. When Running System.InvalidOperationException HResult=0x80131509 Message=A named connection string was used, but the name 'BookStoreDb' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application. See go.microsoft.com/fwlink/?linkid=850912 for more information. Source=Microsoft.EntityFrameworkCore.Relational StackTrace: at Microsoft.EntityFrameworkCore.Storage.Internal.NamedConnectionStringResolverBase.ResolveConnectionString(String connectionString) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection..ctor(RelationalConnectionDependencies dependencies) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection..ctor(RelationalConnectionDependencies dependencies) at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
@georgezanfir4 жыл бұрын
@@beautifulcultures1210 I have the same error did you find any method to make it work?
@CuriousDrive4 жыл бұрын
@@beautifulcultures1210 To fix this issue you will have to add DBContext in your services. ConfigureServices function in your startup.cs class should look something like this. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BookStoresDB"))); } Let me know if you are still facing this issue
@georgezanfir4 жыл бұрын
@@CuriousDrive Hi, i just did that but i still get the error that i don't have an Iconfiguration, Solved: Restart Visual studio
@rigofutty51722 жыл бұрын
#CuriousDrive , Need to encrypt the "connection string" stored in appsettings.json? (before published) If yes, How do it? (asp.net 6) . Thank you for your answer!
@CuriousDrive2 жыл бұрын
I don't think you should encrypt the connection string but you do not need to store somewhere safe. .NET team suggests to store it in user-secrets. Please check out this section - docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding?tabs=dotnet-core-cli#configuration-and-user-secrets
@bhavyar29862 жыл бұрын
Im lucky to find this playlist
@rabahkhiari8621 Жыл бұрын
who get erreur of sertification SSL you have to Add " ;TrustServerCertificate=true "to the connection string. This will force the client to trust the certificate without validation.
@kandinagireddy Жыл бұрын
Tutorial is very good. Are there any new series on .Net 6/7/8/ Web api??
@deepanshukumar39434 жыл бұрын
Best video.. Thank u so much sir..
@CuriousDrive4 жыл бұрын
Thanks for watching Deepanshu. Please share with your friends :)
@2005bgva4 жыл бұрын
Thanks for the video. I have a question, what happened if instead of Scaffold into API we have a CLASS LIBRARY and we want to Scaffold into it? how to Scaffold with a connection name? I tried and the error that I had is "A named connection string was used, but the name 'BookStoresDB' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider" I also added into API Startup.ConfigureServices method this code: "services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BookStoresDB")));"
@CuriousDrive4 жыл бұрын
You will have to add connection string in the API project too. As the API will make the actual connection not the class library.
@2005bgva4 жыл бұрын
@@CuriousDrive The problem persist, I had added a connection string to file "launchSettings.json" but the message is the same "A named connection string was used,......." What I have to do is to follow the comment wrote by @Yakuza 3 months ago, but I would like to understand the reason why with you work and with me do not. these are the steps: into AuthorConstructor: private readonly BookStoresDBContext _context; public AuthorController(BookStoresDBContext context) {_context = context;} return _context.Authors.ToList(); into Startup.cs method "ConfigureServices" string connectionString = Configuration.GetConnectionString("BookStoresDB"); services.AddDbContext(options => options.UseSqlServer(connectionString));
@Hamdymohamedmohamed4 жыл бұрын
is there any way to scaffold the stored procedures too?
@CuriousDrive4 жыл бұрын
Hello Hamdy, you wiill have to do that manually. Please check out this answer on the StackOveflow stackoverflow.com/a/47353442/12014626
@ayushtyagi93913 жыл бұрын
When I am trying to make dbcontext and model classes under the classs librery models folder using scaffold its succedded but unable to have dbcontext and model classs after using it any help will be appreciated ?
@CuriousDrive3 жыл бұрын
Hello Ayush, are there multiple projects in your solution? Please follow below answer from stack overflow. stackoverflow.com/a/58763414/12014626
@shravansangi61045 жыл бұрын
Hi Dear, I have a question in DB First approach.. how to exclude 2 tables out of n tables because those two tables are not going to use in my application and those tables don't have primary key that is throwing an exception. Those tables will be used by SQL jobs in the backend we need to have those tables but don't have to generate models for those tables.. could you please help me? Waiting for your answer.. Thank you.
@CuriousDrive5 жыл бұрын
Unfortunately, Scaffold-DbContext does not take -ExcludeTables as one of the arguments. But it does take -Tables, where you will have to mention all the table names for which you want models to be created.
@shravansangi61045 жыл бұрын
Yeah, that is okay but I have to include approximately 120 tables Every time whenever DB has alter statements that is not good practice for everyone. Thank you for your quick response..
@CuriousDrive5 жыл бұрын
@@shravansangi6104 I know right. Hopefully in their next release they do something about it. You can post this as an enhancement on EF Core github repo.
@allanoloo23914 жыл бұрын
I am running into a issue that says 'No context type was found in the assembly ' I have searched various developer sites and no solution seems to help me resolve this issue. Can you help?
@allanoloo23914 жыл бұрын
forum.codewithmosh.com/d/532-asp-net-mvc-entity-framework-no-context-type-was-found-in-the-assembly Sites like these provide solutions, but they are not working for me :(
@CuriousDrive4 жыл бұрын
When do you get this error? When you run the application or when you run the command?
@Rise2Fate2 жыл бұрын
Great tutorial. Is it possible to use postgre instead of SQL
@capialroja88803 жыл бұрын
Hi! Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Help Me
@CuriousDrive3 жыл бұрын
Hello Capi, sorry that it is not working for you. Are you running this package manager console? I usually get this error when I run into an error in powershell. Please check below articles for running the command in package manager. docs.microsoft.com/en-us/ef/core/cli/powershell docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding?tabs=dotnet-core-cli
@TripuranaLohit4 жыл бұрын
Hi, I tried to Scaffold-DbContext storing connection string and updating in the app setting and also using scaffolding db contect in package manager console to update connection string. I have an issue after I ran the Scaffold-DbContext, it's showing error "Format of the initialization string does not conform to specification starting at index 0" . Please advise me accrdingly
@CuriousDrive4 жыл бұрын
Can you please share your appsettings.json file here?
@DecentProgrammer4 жыл бұрын
Very Helpful
@CuriousDrive4 жыл бұрын
Thanks for the feedback Decent Programmer.
@awais21275 жыл бұрын
Nice Series.
@CuriousDrive5 жыл бұрын
Thanks Muhammad, I am gonna be making more videos on querying and saving relational data. So stay tuned!!
@Program2live4 жыл бұрын
Issue here: I know you have addressed this in a previous comment but it doesn't work. 'A named connection string was used, but the name 'UserDB' was not found in the application's configuration. appsettings file (I added the following): "ConnectionStrings": { "UserDB": "Server=Localhost;Database=UserDB;Trusted_Connection=True;" } Then I done the command: Scaffold-DbContext -Connection Name=UserDB Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force Then I cleaned and rebuilt the project. Still the error is 'A named connection string was used, but the name 'UserDB' was not found in the application's configuration. So, then I added (in ConfigureServices(IServiceCollection services) method): services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("UserDB"))); rebuilt and restarted VS. Still get the error! Any solution to this would be greatly appreciated!
@CuriousDrive4 жыл бұрын
CT, did you add below line in ConfigureServices of StartUp.cs? services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BookStoresDB")));
@Program2live4 жыл бұрын
@@CuriousDrive Hi yeah, i did that and it still didn't work. But fortunetly @Yakuza replied to a comment and the solution for me was to do: string connectionString = Configuration.GetConnectionString("BookStoreDb"); and then services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString(connectionString))); Very strange, and seems like a bug in visual studio or something bizarre, thanks for your videos though they really helped a ton! :D
@naunihalsidhu4 жыл бұрын
Did you try using scaffold command with connection name when using seperate class project ?
@CuriousDrive4 жыл бұрын
Hello Naunihal, that should work just fine as scaffolding command is a CLI command. It does not matter where you are creating your DBContenxt and your models.
You using MySQL server but in scaffolding command you are passing SQL server as a provider. That could be the reason why you getting an error
@manipathak42964 жыл бұрын
Can you please provide how to impliment the entity framework with database first approch and stored procedure?
@CuriousDrive4 жыл бұрын
That is a really good suggestion. I will let you know when I post a tutorial for it. Thanks again
@manipathak42964 жыл бұрын
Hey sorry my bad, just correcting my statement implementation of stored procedure (CRUD) for legacy application in entity framework core database first approch. I tried to do it with ado. Net and is successful but still we are not able to implement repository pattern and added stuff of core functionality which is bad practice. 😃
@Marv3Lthe14 жыл бұрын
I wonder why such a useful feature is not built into visual studio itself? There should be a UI to point to the database, and select the tables I want to scaffold. Just like they have EDMX file UI in .Net framework.
@CuriousDrive4 жыл бұрын
Entity Framework Core still new and EDMX file support will eventually get added in EF Core too. Believe me I am waiting too. :)
@CLU7CH3R4 жыл бұрын
@@lukevincent4397 Thanks, that extension completely replaced all of the instructions in this video. There's even an option to pluralize dbsets.
@talkathiriify5 жыл бұрын
Lovely Thanks a lot.
@baktay4 жыл бұрын
The project did not run after I updated the appsettings.json with connectionstring, and used Scaffold-DbContext -Connection option. I got error: InvalidOperationException: A named connection string was used, but the name 'BookStoresDB' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application.
@CuriousDrive4 жыл бұрын
I was getting that same error when I used it for the first time. I named the value as "ConnectionString" instead of "ConnectionStrings" in appsettings.json. I would recommend checking that first.
@baktay4 жыл бұрын
@@CuriousDrive I have that right actually. On your next vid EP02 you said to add: services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BookStoresDB"))); to Startup.cs ConfigureServices, so I did. I still get the error when running localhost:xxxx/author (also "launchUrl": "author", in launchSettings.json Note: My scaffolding worked however PublishersController ("launchUrl": "api/Publishers",)
@mp-ot7fw4 жыл бұрын
@@baktay I have not seen why this is happening. However I combined the suggested Startup Services code with the following in the Context OnConfiguring Method. It is working for the time being: if (!optionsBuilder.IsConfigured) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json") .Build(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("MYDB")); }
@lukagogrichiani87344 жыл бұрын
worked thanks
@GlitchInMatrix4 жыл бұрын
it may work for you now but good luck retyping it everytime you update database
@abhishekvaze47584 жыл бұрын
I have a postgre sql database at remote location. Can I still scaffold it and use above code to retrieve data from it ?
@CuriousDrive4 жыл бұрын
Hello Abhishek, you will have to install a different nuget package the postgre database provider. you can find that here www.nuget.org/packages/Npgsql.EntityFrameworkCore.PostgreSQL
@rv95702 жыл бұрын
Amazing tutorial. Please can you make a vidoe that shows how we can create this manually to connect the database and create models and all. Thansk in advance
@SatyamSingh-kz5kj4 жыл бұрын
Sir I need some help regarding my project...how can I contact you...
@CuriousDrive4 жыл бұрын
We can talk here Satyam, what's you question?
@SatyamSingh-kz5kj4 жыл бұрын
I want what help can l get if I join your channel...?
@SatyamSingh-kz5kj4 жыл бұрын
Currently I am working in a IT company their they have kept an assessment on entity framework core and web api which is not relevant to me bcoz I have not studied earlier...so I need your help to clear the assessment...
@stefanstefanov98604 жыл бұрын
And a second thing if you use the tool - Bricelam, be careful because if one of your tables is in plural - my was cases, it changes the class to singular - cas, not case. Its not precise in that, so best practise, name your tables singular
@CuriousDrive4 жыл бұрын
Good observation. Thanks for sharing with others :)
@muhammadusama52514 жыл бұрын
When run this "Scaffold-DbContext -Connection Name=dbbook Microsoft.EntityFrameworkCore.SqlServer -OutputDir DbModels" command in class librairy find error like "A named connection string was used, but the name 'NEAProjectdb' was not found in the application's configuration." if any one have idea about this issue kindly help....
@CuriousDrive4 жыл бұрын
Hey Muhammad, did you add "dbbook" in your appsettings.json file? Also the connection strings needs to be correct to make it work. Your command seems correct to me.
@muhammadusama52514 жыл бұрын
@@CuriousDrive thanks sir my issue solved
@reddeimon4753 жыл бұрын
what to do if my Tables name has $ character?
@CuriousDrive3 жыл бұрын
It removes "$" when it scaffolds the database into models
@reddeimon4753 жыл бұрын
@@CuriousDrive I mean to scaffold a specific table using -Tables. The command give an error if any of the table name has special characters or space. Like "Table$ Name". A stack overflow suggest to write -Tables "[dbo].[Table$ name]". The scaffolding run without any error but it actually just ignore the table and no models or context made
@CuriousDrive3 жыл бұрын
@@reddeimon475 I know what you are talking about. I have encountered this issue too. In that case I would scaffold all the tables and delete the models that I don't need. Also check out EF Core Power Tool extension for Visual Studio. That might make your life easier.
@Manu-wb2uv4 жыл бұрын
After adding the pluggin to plurarize the dbsets names I get this error when I scaffold: PM> Scaffold-DbContext -Connection Name=BookStoresDB Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force Build started... Build failed.
@Manu-wb2uv4 жыл бұрын
Oh you need to build the solution and make sure everything is working before you run the command
@CuriousDrive4 жыл бұрын
I am glad that you figured it out. Yes you will have to build the project before running the scaffolding command. I ran into the same issue when I was doing this for the first time.
@namnntt4 жыл бұрын
No text versions?
@CuriousDrive4 жыл бұрын
Nam Nt, I don't completely understand your question. Can you please elaborate?
@talkathiriify5 жыл бұрын
Dear Sir Thank you very much for the best and simplest tutorials i ever seen, With Db first approach is there away to update the production DataBase without losing any data on it, because it is alive data? Thanks a lot.
@CuriousDrive5 жыл бұрын
When you say update, do you mean to test on it?
@talkathiriify5 жыл бұрын
@@CuriousDrive No i mean update the database in a production with the new structure changes. Thank you very much
@CuriousDrive5 жыл бұрын
@@talkathiriify In that case, you will either need to know SQL queries to update the structure or you can go with Entity Framework Code first approach. I am going to start a series on code first approach soon.
@arunkumarsingh87545 жыл бұрын
Keep it up
@CuriousDrive5 жыл бұрын
Yes. more content coming.
@stefanstefanov98604 жыл бұрын
If you are using Mac my friends, you can dotnet tool install --global dotnet-ef dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models And if you need the example with json setting dotnet ef dbcontext scaffold Name=Name_here Microsoft.EntityFrameworkCore.SqlServer -o Models --force
@CuriousDrive4 жыл бұрын
Hi Stefan. Thank you so much for your comment. This is will be useful for people using Mac or Linux. We need people like you in our community. Thanks again!!!
@stefanstefanov98604 жыл бұрын
@@CuriousDrive I am building an app based on your videos on blazor and this api. If I find something I will comment. And just a suggestion, can you provide a video for the api not with custom authorization and authentication, but something like identity server ?
@CuriousDrive4 жыл бұрын
I am glad that you are building an app while watching the videos. For some of the videos, I am going to fast so if you run into any issues or you have questions, feel free ask questions. I am here to help. Also, please like, comment and share with your friends it really helps.
@billjustice94764 жыл бұрын
I believe this video series is going to help me a lot, but I am having the same connection string issue. After hours of trying everything posted here and researching on the internet, I have returned to hard coding it in the context file, just so I can move forward. If anyone has anything new to try, please post. thanks!
@CuriousDrive4 жыл бұрын
Hello Bill, you need to add below line in ConfigureServices method of your StartUp.cs before you scaffold. That should fix the issue. Let me know services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("BookStoresDB")));
@billjustice94764 жыл бұрын
@@CuriousDrive Thank you. I had tried that and other suggestions in this thread prior to posting, but when I set the context folder back to using the ConnectionString name vs. spelling it out just now, my new controllers (the ones I had scaffolded) worked, but not the one we created early in the tutorial as a copy of the weather controller. When I renamed it and applied scaffolding to the same table, it worked just fine. Thanks again : )
@atTran-fs3it3 жыл бұрын
you should have run code before end the video :v
@CuriousDrive3 жыл бұрын
I don't think there was a need as we did not change anything in the logic. is it not building for you?
@nurwantoade50024 жыл бұрын
your intonation to flat, i don't understand
@CuriousDrive4 жыл бұрын
Yes, I wasn't really good at the audio settings in the earlier videos. I bought new microphone to make that better. It gets better as you progress.
@DriveU8364 жыл бұрын
Hey, you made a big Jump from Episode 1 to Episode 2 you lost your audience by not showing Modelling Step by Step with due attention to Navigating Properties and Foreign Keys etc. This is my opinion. You might be right in doing what you seem to be doing but in reality, you left a void. I am not being rude mind this is just healthy criticism to improve from a well-wisher. I was to recommend the best to a coworker for him to get a jump start.
@CuriousDrive4 жыл бұрын
Thank you so much for your feedback. Now that I think about it, I should have squeezed an episode explaining navigation properties. You are not being rude. I like your feedback. You should read some other comments on the channel where people think they own me lol. You are fine. Thanks for the feedback again. I will add this episode in my .NET 5 series which I am planning on starting in November.
@DriveU8364 жыл бұрын
@@CuriousDrive Your supporting code has models defined?
@CuriousDrive4 жыл бұрын
You mean the code on GitHub? Yes I reverse engineered the database and created models
@akrooma3 жыл бұрын
damn! i hate API's!
@CuriousDrive3 жыл бұрын
Lol why?
@akrooma3 жыл бұрын
@@CuriousDrive can't understand the configuration.. so many syntax i type as copy /paste without even understanding it