C
C#ā€¢7mo ago
Rj

Incorrect syntax near the keyword 'NOT'. error during ef database update

I've been following a Asp.net core web api tutorial https://www.youtube.com/watch?v=SIQhe-yt3mA&t=436s and I keep getting this error when trying to do the dotnet ef database update command. I've tried lots of things, but I'm a bit stumped here Error Number:156,State:1,Class:15 Incorrect syntax near the keyword 'NOT'.
Teddy Smith
YouTube
ASP.NET Core Web API .NET 8 2024 - 3. Entity Framework
ASP.NET Core Web API .NET 8 2024 - 3. Entity Framework Github: https://github.com/teddysmithdev/FinShark SQL Server Connection String Template (WINDOWS):
"Data Source={PCNAME}\SQLEXPRESS;Initial Catalog={DATABASENAME};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSub...
No description
126 Replies
Pobiega
Pobiegaā€¢7mo ago
you'll need to show your code
Rj
RjOPā€¢7mo ago
I did on my first post :( it was on the code review what particular files?
Pobiega
Pobiegaā€¢7mo ago
just upload it all to github tbh, much easier for everyone
Rj
RjOPā€¢7mo ago
okay
Pobiega
Pobiegaā€¢7mo ago
what database engine are you using? looks like mssql based on what connector its using but what version?
Rj
RjOPā€¢7mo ago
ssms
Pobiega
Pobiegaā€¢7mo ago
your error is that the SQL server responded that the query is invalid, which is weird since ... "NOT NULL" in a create table is definately valid SSMS isnt a database, its a database client
Rj
RjOPā€¢7mo ago
AHHHH sqlexpress
Pobiega
Pobiegaā€¢7mo ago
right
Rj
RjOPā€¢7mo ago
um hear me out
Pobiega
Pobiegaā€¢7mo ago
try running that query manually in SSMS, just to see if it works?
Rj
RjOPā€¢7mo ago
Im gonna need to download the github thing okay
Pobiega
Pobiegaā€¢7mo ago
can do it in a transaction, if you dont want it saved you dont need to download the github thing - VS has built in git and you dont need their client in fact, I think their client is trash
Rj
RjOPā€¢7mo ago
yea the guy was using vscode im trying not to kms rn
Pobiega
Pobiegaā€¢7mo ago
vscode also has built in git šŸ™‚
Rj
RjOPā€¢7mo ago
WHERE IS IT I founmd ioit
Pobiega
Pobiegaā€¢7mo ago
BEGIN TRAN;
CREATE TABLE ... -- your code here, cant copypaste from an image...

ROLLBACK TRAN;
BEGIN TRAN;
CREATE TABLE ... -- your code here, cant copypaste from an image...

ROLLBACK TRAN;
Pobiega
Pobiegaā€¢7mo ago
404
Rj
RjOPā€¢7mo ago
can u see a private one orr...
Pobiega
Pobiegaā€¢7mo ago
no, thats what private means :p
Rj
RjOPā€¢7mo ago
im so sorry man this site is too godamn big
Pobiega
Pobiegaā€¢7mo ago
ignore git for now then, run the query
Rj
RjOPā€¢7mo ago
it's the nots maybe actually
Pobiega
Pobiegaā€¢7mo ago
oh wait I see the error
Rj
RjOPā€¢7mo ago
No description
Pobiega
Pobiegaā€¢7mo ago
decimal (18,2
Rj
RjOPā€¢7mo ago
omg
Pobiega
Pobiegaā€¢7mo ago
.. did you write the query yourself?
Rj
RjOPā€¢7mo ago
no
Pobiega
Pobiegaā€¢7mo ago
I find it unlikely that EF would generate an invalid query
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
model idk
Pobiega
Pobiegaā€¢7mo ago
look at your typenames wtf >_>
Rj
RjOPā€¢7mo ago
LMFAOOO no it wasn't doing it itself i was having to do it I was going to i promise
Pobiega
Pobiegaā€¢7mo ago
repeat after me: I will use IEntityTypeConfiguration<T> in the future, not the silly attributes
Rj
RjOPā€¢7mo ago
WHAT IN THE FUCJ what
Pobiega
Pobiegaā€¢7mo ago
configuring your models with [Bla] is not recommended
Rj
RjOPā€¢7mo ago
woah
Pobiega
Pobiegaā€¢7mo ago
only a very small subset of configuration can be done with attributes and also lead to shit like this
Rj
RjOPā€¢7mo ago
yea it was too easy :\
Pobiega
Pobiegaā€¢7mo ago
explicit IEntityTypeConfigurations are better. anyways, easy fix - fix your attributes, remove the migration and snapshot, generate a new migration
Rj
RjOPā€¢7mo ago
bro I might cry
No description
Rj
RjOPā€¢7mo ago
im not even on a chatbot
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
why
Pobiega
Pobiegaā€¢7mo ago
... what
Rj
RjOPā€¢7mo ago
idk
Pobiega
Pobiegaā€¢7mo ago
why are people alergic to the documentation
Rj
RjOPā€¢7mo ago
god I looked
Pobiega
Pobiegaā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
it was words and more documentation
Pobiega
Pobiegaā€¢7mo ago
top 2 results
Rj
RjOPā€¢7mo ago
yes I have it open šŸ˜­
Rj
RjOPā€¢7mo ago
yea I was like where is that exactly like in the model?
Pobiega
Pobiegaā€¢7mo ago
no a separate class
public class BlogEntityTypeConfiguration : IEntityTypeConfiguration<Blog>
{
public void Configure(EntityTypeBuilder<Blog> builder)
{
builder
.Property(b => b.Url)
.IsRequired();
}
}
public class BlogEntityTypeConfiguration : IEntityTypeConfiguration<Blog>
{
public void Configure(EntityTypeBuilder<Blog> builder)
{
builder
.Property(b => b.Url)
.IsRequired();
}
}
this class configures EF for Blog
Rj
RjOPā€¢7mo ago
so can i put this in data or is this a model thing
Pobiega
Pobiegaā€¢7mo ago
its an EF thing. it should live near your context.
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
my current files
Pobiega
Pobiegaā€¢7mo ago
if your Context is at Project.Data, I'd put it in Project.Data.Configurations
Rj
RjOPā€¢7mo ago
okay
Pobiega
Pobiegaā€¢7mo ago
then do modelBuilder.ApplyConfigurationsFromAssembly(typeof(BlogEntityTypeConfiguration).Assembly); in your contexts OnModelConfiguring to load all the configs you dont need the attribute to associate the model with the config bit of a rant thou, why are young coders so against reading docs
Rj
RjOPā€¢7mo ago
lmfdaoooo idk it's more because it's all abstract things
Pobiega
Pobiegaā€¢7mo ago
sure, documentation is long and wordy, but thats cause its not a direct answer to a single question, its describing an entire section or feature
Rj
RjOPā€¢7mo ago
and I'm like sitting here rn thinking god I hate following tutorials okay I name this FInshark Configurations orsomething like FinsharkConfigurations and then or stock
Pobiega
Pobiegaā€¢7mo ago
generally you make one of these for each model
Rj
RjOPā€¢7mo ago
yea stockentitytypeconfiguration okay
Pobiega
Pobiegaā€¢7mo ago
so the config for Stockwould be internal class StockConfiguration : IEntityTypeConfigration<Stock> eh, maybe make it public, doesnt really matter
Rj
RjOPā€¢7mo ago
why does my vscode hate me
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
it says is a reference missing HELP ME VSCODE HELP ME THEN GIVE ME THE REFERENCE PAL šŸ˜­
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
okay I was being an asshole it worked except the url thing
Pobiega
Pobiegaā€¢7mo ago
uuh why is it nested
Rj
RjOPā€¢7mo ago
dude
Rj
RjOPā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
okay
Pobiega
Pobiegaā€¢7mo ago
cursed indentation :p but sure
Rj
RjOPā€¢7mo ago
is the url thing fine or am i dead
Pobiega
Pobiegaā€¢7mo ago
do you have a property called Uri?
Rj
RjOPā€¢7mo ago
not that I've been using this far in my minmdddd I can go check nope
Pobiega
Pobiegaā€¢7mo ago
based on the model you showed before, you'd configure the properties for Profit and Purchase since you had changed their types
Rj
RjOPā€¢7mo ago
can I get rid of them :)))
Pobiega
Pobiegaā€¢7mo ago
wdym? if you dont need to configure them at all, then why have we just wasted 15 min setting up entity configuration?
Rj
RjOPā€¢7mo ago
eh ykw lets keep going but if the numbers truly were the issue omfg
Pobiega
Pobiegaā€¢7mo ago
...
Rj
RjOPā€¢7mo ago
it's for a tutorial man
Pobiega
Pobiegaā€¢7mo ago
the numbers were not the issue
Rj
RjOPā€¢7mo ago
oh see
Pobiega
Pobiegaā€¢7mo ago
the issue was THE MISSING PARENTHESIS
Rj
RjOPā€¢7mo ago
I can't fix that
Pobiega
Pobiegaā€¢7mo ago
decimal(18,2 is NOT THE SAME as decimal(18,2)
Rj
RjOPā€¢7mo ago
I didn't make it
Pobiega
Pobiegaā€¢7mo ago
"I cant fix that" sure you can
Rj
RjOPā€¢7mo ago
is fixing it
Pobiega
Pobiegaā€¢7mo ago
you have the file ON YOUR COMPUTER >_> its literally two characters jesusadxgfhujbsanojfgas
Rj
RjOPā€¢7mo ago
lmfaooo well long route works idrk how would I fix that tho
Pobiega
Pobiegaā€¢7mo ago
what are you fucking on about LOOK AT YOUR MODEL
Rj
RjOPā€¢7mo ago
hm its not
Pobiega
Pobiegaā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
LFMAOOO
Pobiega
Pobiegaā€¢7mo ago
blind legally blind illegally blind? maybe.
Rj
RjOPā€¢7mo ago
hm. touche why why did you walk me down that long ass road just to stop me there
Pobiega
Pobiegaā€¢7mo ago
No description
Rj
RjOPā€¢7mo ago
we were about to embark on like one piece or smth
Pobiega
Pobiegaā€¢7mo ago
I pointed it out 30 min ago
Rj
RjOPā€¢7mo ago
hey
Pobiega
Pobiegaā€¢7mo ago
but you should not do EF configuration using DataAnnotation attributes
SleepWellPupper
SleepWellPupperā€¢7mo ago
this is quite entertaining, keep it up guys
Rj
RjOPā€¢7mo ago
this is why I fucking hate this discord omg šŸ˜­
Pobiega
Pobiegaā€¢7mo ago
thats why I said use IETC lol?
Rj
RjOPā€¢7mo ago
im sorry I love you thank you for your help i was laughing my ass off explain this tho so configurations they are like optional right
Pobiega
Pobiegaā€¢7mo ago
in a way
Rj
RjOPā€¢7mo ago
my thing will run with the ones from ms unless I change whatever for whatever I need
Pobiega
Pobiegaā€¢7mo ago
if you dont use configurations in any way, you get the defaults sometimes thats fine sometimes you need to configure stuff
Rj
RjOPā€¢7mo ago
yeaa :3
Pobiega
Pobiegaā€¢7mo ago
there are 3 ways to configure an EF entity 1. data annotations - the attributes you are currently using 2. inside the context 3. with dedicated entity type configration classes 3 is the recommended approach
Rj
RjOPā€¢7mo ago
preach
Pobiega
Pobiegaā€¢7mo ago
1 is what all shitty youtube tutorials do, because their examples are trivial and would you believe it, in a trivial example, you can often get away with it but for configuring a Many-to-Many relationship, or a two way type conversion, or owned entities, you need to use 2 or 3, and 3 is just "cleaner" since its each model for itself instead of all of them in one blob
Rj
RjOPā€¢7mo ago
um so question
Pobiega
Pobiegaā€¢7mo ago
I'm quivering in anticipation
Rj
RjOPā€¢7mo ago
documentation may serve it's purpose for once in my life tbh
Rj
RjOPā€¢7mo ago
GitHub
GitHub - Yeeeef/WebApi
Contribute to Yeeeef/WebApi development by creating an account on GitHub.
Rj
RjOPā€¢7mo ago
got it um okay it's building cool thanks for the help
Want results from more Discord servers?
Add your server