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

Did you find this page helpful?