首页 > 其他分享 >.net6中使用EF core多个上下文迁移方式

.net6中使用EF core多个上下文迁移方式

时间:2024-05-20 16:08:12浏览次数:17  
标签:core EF 添加 Context net6 迁移 上下文

正常上下文在复制一个一模一样的上下文 appsettings.json添加两个数据库连接字符串

 

Program.cs里边一样添加两个

 

控制台迁移命令

必须加上-Context 后边跟的是我们上下文的名称

Add-Migration MyMigration -Context MYDBContext222

保存到数据库命令一样

Update-Database -Context MYDBContext222

记得切换默认迁移的项目

如果不是频繁的使用第二个上下文,就没有必要在做一个仓储基础类,在这里我是只有个别方法使用,所以直接在哪里用在哪里注入就可以了

 

需要再哪里使用注入到哪一层

 

添加方法-并添加事务

 

标签:core,EF,添加,Context,net6,迁移,上下文
From: https://www.cnblogs.com/xiaoyangma/p/18202199

相关文章

  • 论文阅读:Reasoning with Latent Structure Refinement for Document-Level Relation E
    NanG,GuoZ,SekulićI,etal.Reasoningwithlatentstructurerefinementfordocument-levelrelationextraction[J].arXivpreprintarXiv:2005.06312,2020.代码和预训练模型的github链接LSR模型本文提出了用于文档级关系提取任务的LatentStructureRefinement(L......
  • ref和reactive
     所花时间(包括上课): 1 h左右代码量(行): 200  左右搏客量(篇):1了解到的知识点: ref和reactive备注(其他): ref和reactivereactive在修改响应式对象的时候,要用Object.assign(car,{brand:'xiaomi',price:20})需要一个基本类型的响应式数据,必须使......
  • Entity Framwork Core 数据注解(Data Annotations)使用方法
    在EntityFrameworkCore中,数据注解(DataAnnotations)是通过在实体类的属性上使用特性(Attributes)来配置实体与数据库之间的映射关系的一种方式。这种方式比较直观且易于理解,特别适用于简单的配置需求。下面是一些使用数据注解配置实体的C#示例:1.配置主键publicclassBlog{......
  • .NetCore工具
    1、更新GeneralUpdate:Myshiplooksold,whocanhelpmeupgradeit.(gitee.com)GeneralUpdate是一款基于.NETStandard2.0开源自动升级组件。运行环境:.NET7、.NETMAUI、Visualstudio2022(Preview)功能是否支持备注断点续传支持单次更新失败时,下次一次启动时......
  • EasyUEFI、Bootice、Bcdedit和EfiVarCLI都是用于管理计算机启动项和UEFI设置的工具,但
    EasyUEFI、Bootice、Bcdedit和EfiVarCLI都是用于管理计算机启动项和UEFI设置的工具,但它们在功能和用途上有一些区别:EasyUEFI:EasyUEFI是一个用户友好的图形界面工具,主要用于管理UEFI引导项,在Windows操作系统下操作更加方便。EasyUEFI提供了添加、删除、编辑UEFI引导项的......
  • Codeforces Round 945 (Div. 2) (A - E)
    A每一轮对总分的贡献都是\(2\),如果\(p_1+p_2+p_3\)为奇数则无解。\(p_1+p_2\lep_3\),最多\(p_1+p_2\)轮。\(p_1+p_2>p_3\),可以\(1,2\)轮流将\(3\)耗完,然后互相匹配,最多\(\dfrac{p_1+p_2+p_3}{2}\)。B如何判断一个\(k_0\)是否符合条件?处......
  • Reflective Journal III
    ......
  • Reflective Journal ⅲ
    BeforeIdidthisdigitalstory,IwatchedtheSnowWhiteandtheSevenDwarfsmovieagainanditwasreallyinterestingandworthtowatch.Intheprocessofwatching,Itookclipsofsomerepresentativephotosasthematerialofmyvideo.ThenIstarted......
  • reflective journel
    WhenIconfectedmydigitalstory,Idivideditintofourpartsinitially.Firstofall,Ineedtochoseastorywhichhascharmingplotsandprofoundmeaningunderit’ssurface,vividcharacter,etc.sodouble-mindedwereIbecausetherewereabundantst......
  • Reflective Journal III
    (1)Theprocessofmakingadigitalstory:WhenIknewthehomeworkIrememberedtraditionalshortnovelsuchas聊斋.ThecadaverizationappealedtomyinterestandIdecidedtoadaptthisnovel.Aloughthisstoryisappealing,thiskindofChinesetraditional......