Data Annotation Updates in .NET 8

  Рет қаралды 15,051

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 51
@chris_cole
@chris_cole Жыл бұрын
Love these quick and simple videos. I didn't even realize until now that they had added these.
@KarmCraft
@KarmCraft Жыл бұрын
Tim you need to show what happens if you enter an invalid value. Is it design time or runtime? What does it throw?
@aslamsayyedsayyed2885
@aslamsayyedsayyed2885 Жыл бұрын
Lots of love and respect from India. Thanks for your efforts.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@dmytroshchotkin2939
@dmytroshchotkin2939 Жыл бұрын
Thanks, Tim. It would have been nicer if you had shown one use-case scenario. Are the attributes applicable when we deserialize using System.Text serializer only?
@andergarcia1115
@andergarcia1115 Жыл бұрын
Thanks, Master. You're amazing as always.
@anandvgchennai1974
@anandvgchennai1974 Жыл бұрын
Thanks for explaining these new cool features. Next time I think MS should come with LengthAfterTrim (5, 25). Most of the time we check the length of string after trimming the values entered.
@benjaminshinar9509
@benjaminshinar9509 Жыл бұрын
seems nice, but I could really use a demo of those. are they checked at runtime or compile time? do they throw exceptions?
@pw.70
@pw.70 5 ай бұрын
Very useful. Thanks Tim.
@IAmTimCorey
@IAmTimCorey 5 ай бұрын
You are welcome.
@비엠이-l8w
@비엠이-l8w 5 ай бұрын
Thank you for teaching!😊
@IAmTimCorey
@IAmTimCorey 5 ай бұрын
You are welcome.
@Vsd13
@Vsd13 Жыл бұрын
It would be interesting to know what to do with the project after its development, how to upload your project and database to the server. For example, so that I can send a link to the site I created. Maybe you already have a video that indirectly explains this topic?
@shadmansudipto7287
@shadmansudipto7287 Жыл бұрын
What? You need to watch a beginner aspnet tutorial. There are many on KZbin. Why ask him to make yet another? It doesn't add any value to do what is already done.
@marcusreinicke
@marcusreinicke Жыл бұрын
Thx Tim, can combined the allowed and denied values with RegEx matching?
@Don-ii4vm
@Don-ii4vm Жыл бұрын
4:38 Is it possible to dynamically set AllowedValues from a table?
@ajdin3511
@ajdin3511 Жыл бұрын
If its data that is a lookup table(values that dont change often), perhaps a table that stores types of roles user can have, I believe you can just create an enum and use its values in data annotation as allowed values and it should work fine, making it dynamic is an issue i dont think this solves.
@Don-ii4vm
@Don-ii4vm Жыл бұрын
@@ajdin3511 The values dont change often, but they do change and it would be useful if the software didnt need to be recompiled each time.
@anandvgchennai1974
@anandvgchennai1974 Жыл бұрын
I also had the same question in my mind.
@Don-ii4vm
@Don-ii4vm Жыл бұрын
@@anandvgchennai1974 As Luke says, it woiuld be best to write a custom validator in that case.
@anandvgchennai1974
@anandvgchennai1974 Жыл бұрын
@@Don-ii4vm Yes. Thats a good option.
@dotnetdevni
@dotnetdevni Жыл бұрын
i wish they allowed dyanmic annotations so could come from the db
@FernandoZamudioC
@FernandoZamudioC 11 ай бұрын
Thanks for this wonderful videos ! I hace a question...i usually i used a partial class to define this data annotatios but ModelMetadataType in the Microsoft.aspnetCore.mvc is deprecated ! can you helpme ?
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
I believe you just need to use the Core version of the library: learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.modelmetadatatypeattribute?view=aspnetcore-8.0
@BrentHollett
@BrentHollett Жыл бұрын
Do any of these flow to EF and remove the need for some Entity Configuration steps?
@Anton-Os
@Anton-Os Жыл бұрын
Tim, thanks!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@scdecade
@scdecade Жыл бұрын
Hmmm now I'm curious to see the error messages generated by these validations
@queenstownswords
@queenstownswords Жыл бұрын
Hello Tim. Great video. Would you need to check for consistency in the database table, in the class definition annotation (this video) and in a UI text attributes? Is there an annotation for keeping DeniedValues - like something that is not UTF-8 - out of the input?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I always check the data whenever a user has access to create/change it. Never trust the user. Data integrity in the database is a whole different topic and not one you would typically address with these types of rules. As for a non-UTF-8 check, that would probably need to be a custom rule.
@BrandonChawane
@BrandonChawane 7 ай бұрын
Does it mean I no longer need to get/set value in my getter/setter blocks?
@IAmTimCorey
@IAmTimCorey 7 ай бұрын
I don't understand what you mean. If you are asking if you can remove the get/set in a property, the answer is no. The items I covered in this video just check to be sure the data entered is correct.
@BrandonChawane
@BrandonChawane 7 ай бұрын
@@IAmTimCorey oh I see now. Strictly for validation
@kvelez
@kvelez 8 ай бұрын
Cool excellent man.
@IAmTimCorey
@IAmTimCorey 8 ай бұрын
Thanks!
@Maykon861
@Maykon861 7 ай бұрын
Can I validate that there are no duplicate objects in a list?
@IAmTimCorey
@IAmTimCorey 7 ай бұрын
That would need to be a custom validator. Either that or you could use a specific list type that did not allow duplicates like HashSet.
@methic-w1l
@methic-w1l Жыл бұрын
Thanks very useful.
@DDDD-rr6uo
@DDDD-rr6uo Жыл бұрын
Hello IAmTimCorey! I wont you to tell your students when its good to use ai or copilot for coding or how much is it allowed to do so as a new c sharp students who are following your master course
@IAmTimCorey
@IAmTimCorey Жыл бұрын
I would recommend avoiding it when you are learning. Copilot is great, but it isn't always right. Learn how to do things right before you get led astray by code that looks right but actually isn't.
@zohashobbar118
@zohashobbar118 6 ай бұрын
thanks
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
You are welcome.
@swordblaster2596
@swordblaster2596 Жыл бұрын
But what's it FOR?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Data validation. So if you have a user fill out a form, you can check to see if the data is valid according to your rules.
@holger_p
@holger_p Жыл бұрын
@@IAmTimCorey So is there a package like EF or Dabber, processing these annotations, or do I have to do it myself, if you say "you can check" ? If I have to do it myself, I can always define the Annotations myself and the entire thing would be useless - if nobody else is processing it. When I just query a remote database into these annotated classes, does the execution fail, if incoming data are invalid.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
When the user submits a form, the validations can be automatically checked before the submit button is processed (client-side) and once the data is sent to the server (server-side). It isn't something you need to do manually.
@holger_p
@holger_p Жыл бұрын
@@IAmTimCorey OK, the question came up, cause Entity Framework is building a SQL-structure from such kind of annotations, translating MinLength, MaxLength into Datatype NVarChar(min, max) The term "Data annotations" is not unique to validation.
@E_G_
@E_G_ Жыл бұрын
Waiting for BlackFriday Dsicounts :)
@cissemy
@cissemy Жыл бұрын
Thanks
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
Dependency Injection Updates in .NET - Keyed Implementations
8:31
How IDisposable and Using Statements Work Together in C#
10:01
IAmTimCorey
Рет қаралды 33 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
The New Data Protection Features of .NET 8 (GDPR)
14:10
Nick Chapsas
Рет қаралды 51 М.
Dead Simple GUI (Immediate Mode)
15:31
Stian
Рет қаралды 2 М.
Collections Just Changed in C# 12 and That’s Good
8:01
Nick Chapsas
Рет қаралды 105 М.
How To Modernize Your C# Skills in 2025
54:57
IAmTimCorey
Рет қаралды 7 М.
The New Way of Calling Your Code in .NET 8 Is INSANE
12:34
Nick Chapsas
Рет қаралды 139 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН