有誰知道是否可以從表或視圖(EF 連接)的資料中構建 Linqpad 7 中的模型?我有一個包含數百列的表.. 只需右鍵單擊它并選擇“構建模型”(或右鍵單擊 .Dump() 并從那里構建它)會很好。我的意思是它有所有資料,只需要匯出列名和資料型別:-)
uj5u.com熱心網友回復:
您可以嘗試使用Query => Reflect Query in ILSpy選單選項。只需鍵入var a = new MyTableType();并單擊 MyTableType 型別即可找到 EF 創建的代碼。
uj5u.com熱心網友回復:
我最近用 Sqlite 資料庫做過幾次,還有一段時間用 SQL 資料庫做過。
我希望能夠在 Visual Studio 中使用 dll 并且不想依賴 Linqpad,但確實希望能夠在 Linqpad 中使用它。
你不必這樣做,但我使用的程序是這樣的。
在 LinqPad 中選擇資料庫并將腳本
Util.OpenILSpy(typeof(TypedDataContext));作為 C# 運算式運行。在 ILSpy 中,向上滾動到 Assembly 選項卡并右鍵單擊名稱以 TypedDataContext_ 開頭的 dll(參見示例截圖)

從背景關系選單中選擇保存代碼。
打開所選檔案夾并瀏覽到子檔案夾 LinqPad\User。
將模板 csproj 檔案復制到該檔案夾??中,然后打開專案檔案。(注意 ILSpy 將生成自己的 csproj 檔案,如果您不介意依賴 Linqpad,可以使用該檔案并忽略其余說明)
打開 TypedDataContext.cs
洗掉線
using LINQPad.Drivers.EFCore;搜索并替換
ConnectionHelper.CurrentCxString ?? Util.CurrentCxString;為空字串。搜索并替換
TypedDataContext為我自己的背景關系搜索并替換
namespace LINQPad.User為我自己的命名空間。編譯。
Sqlite 專案的 csproj 檔案模板是
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.8" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Proxies">
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Sqlite">
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Relational">
</Reference>
</ItemGroup>
</Project>
我認為SQL的一個是
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.EntityFrameworkCore">
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Proxies">
</Reference>
<Reference Include="Microsoft.EntityFrameworkCore.Relational">
</Reference>
</ItemGroup>
</Project>
顯然這取決于 net6.0 和特定版本的 EF,但你明白了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/506999.html
