C
C#•11mo 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•11mo ago
you'll need to show your code
Rj
RjOP•11mo ago
I did on my first post :( it was on the code review what particular files?
Pobiega
Pobiega•11mo ago
just upload it all to github tbh, much easier for everyone
Rj
RjOP•11mo ago
okay
Pobiega
Pobiega•11mo ago
what database engine are you using? looks like mssql based on what connector its using but what version?
Rj
RjOP•11mo ago
ssms
Pobiega
Pobiega•11mo 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•11mo ago
AHHHH sqlexpress
Pobiega
Pobiega•11mo ago
right
Rj
RjOP•11mo ago
um hear me out
Pobiega
Pobiega•11mo ago
try running that query manually in SSMS, just to see if it works?
Rj
RjOP•11mo ago
Im gonna need to download the github thing okay
Pobiega
Pobiega•11mo 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•11mo ago
yea the guy was using vscode im trying not to kms rn
Pobiega
Pobiega•11mo ago
vscode also has built in git šŸ™‚
Rj
RjOP•11mo ago
WHERE IS IT I founmd ioit
Pobiega
Pobiega•11mo 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•11mo ago
404
Rj
RjOP•11mo ago
can u see a private one orr...
Pobiega
Pobiega•11mo ago
no, thats what private means :p
Rj
RjOP•11mo ago
im so sorry man this site is too godamn big
Pobiega
Pobiega•11mo ago
ignore git for now then, run the query
Rj
RjOP•11mo ago
it's the nots maybe actually
Pobiega
Pobiega•11mo ago
oh wait I see the error
Rj
RjOP•11mo ago
No description
Pobiega
Pobiega•11mo ago
decimal (18,2
Rj
RjOP•11mo ago
omg
Pobiega
Pobiega•11mo ago
.. did you write the query yourself?
Rj
RjOP•11mo ago
no
Pobiega
Pobiega•11mo ago
I find it unlikely that EF would generate an invalid query
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
model idk
Pobiega
Pobiega•11mo ago
look at your typenames wtf >_>
Rj
RjOP•11mo ago
LMFAOOO no it wasn't doing it itself i was having to do it I was going to i promise
Pobiega
Pobiega•11mo ago
repeat after me: I will use IEntityTypeConfiguration<T> in the future, not the silly attributes
Rj
RjOP•11mo ago
WHAT IN THE FUCJ what
Pobiega
Pobiega•11mo ago
configuring your models with [Bla] is not recommended
Rj
RjOP•11mo ago
woah
Pobiega
Pobiega•11mo ago
only a very small subset of configuration can be done with attributes and also lead to shit like this
Rj
RjOP•11mo ago
yea it was too easy :\
Pobiega
Pobiega•11mo ago
explicit IEntityTypeConfigurations are better. anyways, easy fix - fix your attributes, remove the migration and snapshot, generate a new migration
Rj
RjOP•11mo ago
bro I might cry
No description
Rj
RjOP•11mo ago
im not even on a chatbot
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
why
Pobiega
Pobiega•11mo ago
... what
Rj
RjOP•11mo ago
idk
Pobiega
Pobiega•11mo ago
why are people alergic to the documentation
Rj
RjOP•11mo ago
god I looked
Pobiega
Pobiega•11mo ago
No description
Rj
RjOP•11mo ago
it was words and more documentation
Pobiega
Pobiega•11mo ago
top 2 results
Rj
RjOP•11mo ago
yes I have it open 😭
Rj
RjOP•11mo ago
yea I was like where is that exactly like in the model?
Pobiega
Pobiega•11mo 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•11mo ago
so can i put this in data or is this a model thing
Pobiega
Pobiega•11mo ago
its an EF thing. it should live near your context.
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
my current files
Pobiega
Pobiega•11mo ago
if your Context is at Project.Data, I'd put it in Project.Data.Configurations
Rj
RjOP•11mo ago
okay
Pobiega
Pobiega•11mo 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•11mo ago
lmfdaoooo idk it's more because it's all abstract things
Pobiega
Pobiega•11mo 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•11mo 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•11mo ago
generally you make one of these for each model
Rj
RjOP•11mo ago
yea stockentitytypeconfiguration okay
Pobiega
Pobiega•11mo ago
so the config for Stockwould be internal class StockConfiguration : IEntityTypeConfigration<Stock> eh, maybe make it public, doesnt really matter
Rj
RjOP•11mo ago
why does my vscode hate me
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
it says is a reference missing HELP ME VSCODE HELP ME THEN GIVE ME THE REFERENCE PAL 😭
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
okay I was being an asshole it worked except the url thing
Pobiega
Pobiega•11mo ago
uuh why is it nested
Rj
RjOP•11mo ago
dude
Rj
RjOP•11mo ago
No description
Rj
RjOP•11mo ago
okay
Pobiega
Pobiega•11mo ago
cursed indentation :p but sure
Rj
RjOP•11mo ago
is the url thing fine or am i dead
Pobiega
Pobiega•11mo ago
do you have a property called Uri?
Rj
RjOP•11mo ago
not that I've been using this far in my minmdddd I can go check nope
Pobiega
Pobiega•11mo 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•11mo ago
can I get rid of them :)))
Pobiega
Pobiega•11mo 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•11mo ago
eh ykw lets keep going but if the numbers truly were the issue omfg
Pobiega
Pobiega•11mo ago
...
Rj
RjOP•11mo ago
it's for a tutorial man
Pobiega
Pobiega•11mo ago
the numbers were not the issue
Rj
RjOP•11mo ago
oh see
Pobiega
Pobiega•11mo ago
the issue was THE MISSING PARENTHESIS
Rj
RjOP•11mo ago
I can't fix that
Pobiega
Pobiega•11mo ago
decimal(18,2 is NOT THE SAME as decimal(18,2)
Rj
RjOP•11mo ago
I didn't make it
Pobiega
Pobiega•11mo ago
"I cant fix that" sure you can
Rj
RjOP•11mo ago
is fixing it
Pobiega
Pobiega•11mo ago
you have the file ON YOUR COMPUTER >_> its literally two characters jesusadxgfhujbsanojfgas
Rj
RjOP•11mo ago
lmfaooo well long route works idrk how would I fix that tho
Pobiega
Pobiega•11mo ago
what are you fucking on about LOOK AT YOUR MODEL
Rj
RjOP•11mo ago
hm its not
Pobiega
Pobiega•11mo ago
No description
Rj
RjOP•11mo ago
LFMAOOO
Pobiega
Pobiega•11mo ago
blind legally blind illegally blind? maybe.
Rj
RjOP•11mo ago
hm. touche why why did you walk me down that long ass road just to stop me there
Pobiega
Pobiega•11mo ago
No description
Rj
RjOP•11mo ago
we were about to embark on like one piece or smth
Pobiega
Pobiega•11mo ago
I pointed it out 30 min ago
Rj
RjOP•11mo ago
hey
Pobiega
Pobiega•11mo ago
but you should not do EF configuration using DataAnnotation attributes
SleepWellPupper
SleepWellPupper•11mo ago
this is quite entertaining, keep it up guys
Rj
RjOP•11mo ago
this is why I fucking hate this discord omg 😭
Pobiega
Pobiega•11mo ago
thats why I said use IETC lol?
Rj
RjOP•11mo 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•11mo ago
in a way
Rj
RjOP•11mo ago
my thing will run with the ones from ms unless I change whatever for whatever I need
Pobiega
Pobiega•11mo ago
if you dont use configurations in any way, you get the defaults sometimes thats fine sometimes you need to configure stuff
Rj
RjOP•11mo ago
yeaa :3
Pobiega
Pobiega•11mo 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•11mo ago
preach
Pobiega
Pobiega•11mo 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•11mo ago
um so question
Pobiega
Pobiega•11mo ago
I'm quivering in anticipation
Rj
RjOP•11mo ago
documentation may serve it's purpose for once in my life tbh
Rj
RjOP•11mo ago
GitHub
GitHub - Yeeeef/WebApi
Contribute to Yeeeef/WebApi development by creating an account on GitHub.
Rj
RjOP•11mo ago
got it um okay it's building cool thanks for the help

Did you find this page helpful?