Scaffold-DbContext ignores table after updating to EF Core ...

文章推薦指數: 80 %
投票人數:10人

Tools) 6.0.5 I noticed that when running Scaffold-DbContext , a table in the database is completely ignored and no class for it is being ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams Scaffold-DbContextignorestableafterupdatingtoEFCoretools6.0.5 AskQuestion Asked 4monthsago Modified 4monthsago Viewed 659times 0 AfterupdatingfromEFCoreTools5toEFCoretools(Microsoft.EntityFrameworkCore.Tools)6.0.5InoticedthatwhenrunningScaffold-DbContext,atableinthedatabaseiscompletelyignoredandnoclassforitisbeinggenerated.ThedatabasestructureisrathercomplexsoIdon'tknowwhatexactlycausesthisproblembuttheclasswhichwasgeneratedinpreviousversionsoftheEFCoretoolslookedlikethis: publicpartialclassTableName { publicstringId{get;set;} publicintTypeId{get;set;} publicvirtualRelatedTable1Related1{get;set;} publicvirtualRelatedTable2Related2{get;set;} } WheninspectingthegeneratedcodeinOnModelCreating,Ifoundoutthatthetoolsareinfactawareoftheexistenceofthistable.Forexample,inthemodelBuildercodeforanothertablewhichisrelatedtothemissingtable,aUsingEntitycalllikethisisbeingadded: entity.HasMany(d=>d.Types) .WithMany(p=>p.Related1) .UsingEntity>( "TableName", l=>l.HasOne().WithMany().HasForeignKey("TypeId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("TBL_..."), r=>r.HasOne().WithMany().HasForeignKey("Id").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("TBL_..."), j=> { j.HasKey("Id","TypeId"); j.ToTable("..."); j.HasIndex(new[]{"TypeId"},"IX_T..._type_ID"); j.IndexerProperty("Id").HasMaxLength(50).HasColumnName("id"); j.IndexerProperty("TypeId").HasColumnName("type_ID"); }); Whydoesitdecidetodothisinsteadofgeneratingaclassforthistable?Didanyoneexperiencesimilarproblemslikethisandhasanideawhatcausesthisproblemandwhatcanbedoneaboutit? UPDATE: AfterlookingthroughthebreakingchangesinEFCore6,Ifoundthischangewhichmightbeexactlywhatcausesthisprobleminmyproject.However,Idon'tyetfullyunderstandhowIamsupposedtoupdatemycodesoIdon'thavetodowngradeagainoraddanyadditionalstepstodoeverytimeIrunScaffold-DbContextagain. c#sql-serverentity-framework-corescaffoldingef-core-6.0 Share Improvethisquestion Follow editedMay18at8:51 Chris askedMay18at8:14 ChrisChris 66511goldbadge88silverbadges2626bronzebadges 7 Thisisduetomanytomanytablessupportinscaffolding.YoucandisableinEFCorePowerToolstogetpreviousmodelgenerated. – ErikEJ May18at10:31 Readingthedocumentation,itsuggeststhisbehavioronlyapplieswhenthejointabledoesn'thaveanyadditionalattributes,justthe2FK's.Maybeifyouaddanattributetothejoinentity,EFrevertstotheoldbehavior? – pjs May18at10:49 @ErikEJCouldyouexplainwhereexactlythiscanbedisabledinEFCorePowerTools? – Chris May18at10:58 @pjsProbably,butthisjustdoesnotseemlikeagoodsolutiontome.Unlessthereisanoptiontoreverttotheoldbehavior,I'dprefertoadaptmyapplicationcodetowhateverMicrosoftthinkswouldbethe"correct"waytohandlethis.Unfortunately,IdonotreallyunderstandwhatMicrosoftexpectsadevelopertodohere. – Chris May18at13:30 @ChrisYoucandisablethemaytomanymappingandjusthavetheproperentityM2Mentitygenerated – ErikEJ May18at18:14  |  Show2morecomments 0 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) Knowsomeonewhocananswer?Sharealinktothisquestionviaemail,Twitter,orFacebook. YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Browseotherquestionstaggedc#sql-serverentity-framework-corescaffoldingef-core-6.0oraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Related 118 "Buildfailed"onDatabaseFirstScaffold-DbContext 2 EFCore2:Databasefirstwithmany-to-many(linkingtable) 240 NeedtoUpdateEFCoreTools 1 PartialEFContextOnModelCreatingUsingScaffold-DbContext 0 AddingAtabletotheentitywithoutusingScaffoldDbContext 4 ScaffoldEFCoreentitieswithinterface 1 Scaffold-DbContextFails.System.TypeLoadException:Couldnotloadtype'Microsoft.EntityFrameworkCore.Internal.ProductInfo'on.NETCore 0 Recommendedapproachtoshowacustomuserpropertyinaview? HotNetworkQuestions Doyoupayforthebreakfastinadvance? PacifistethosblockingmyprogressinStellaris Whoorwhatis"Nampat"inthechantoftheOrcsintheRingsofPower? Theunusualphrasing"verb+the+comparativeadjective"intheLordoftheRingsnovels StrangeFruitfromTomatoPlant CanIuseaspritesheetfromanexistingvideogameformypromotionalreel? What'sthedifferencebetween'Dynamic','Random',and'Procedural'generations? Howdoyoucalculatethetimeuntilthesteady-stateofadrug? My(large)employerhasn'tregisteredanobviousmisspellingoftheirprimarydomainURL DidMS-DOSeverdropabilitytosupportnon-IBMPCcompatiblemachines? WhydopeopleinsistonusingTikzwhentheycanusesimplerdrawingtools? WhydidGodprohibitwearingofgarmentsofdifferentmaterialsinLeviticus19:19? IfthedrowshadowbladeusesShadowSwordasarangedattack,doesitthrowasword(thatitthenhastoretrievebeforeusingitagain)? Whyarefighterjetssoloudwhendoingslowflight? CommonPlotLegendsforDensityPlot WhatdothecolorsindicateonthisKC135tankerboom? Shouldselectedoptionsberemovedfromsingle-andmulti-selectdropdownlists? Movingframesmethod Howtoelegantlyimplementthisoneusefulobject-orientedfeatureinMathematica? HowtoruntheGUIofWindowsFeaturesOn/OffusingPowershell Howtoremovetikznode? IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? Howtoformalizeagamewhereeachplayerisaprogramhavingaccesstoopponent'scode? ArethereanyspellsotherthanWishthatcanlocateanobjectthroughleadshielding? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?