https://www.cdata.com/kb/tech/odata-ado-linqpad.rst
https://cdn.cdata.com/help/RDG/ado/pg_efCoreConsoleApp.htm
https://cdn.cdata.com/help/RDG/ado/pg_efCoreScaffolding.htm
https://cdn.cdata.com/help/RDG/ado/pg_efCoreASPApp.htm
Install-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.Relational
Install-Package Microsoft.EntityFrameworkCore.Tools
<Reference Include="CData.EntityFrameworkCore.OData">
<HintPath>C:\Program Files\CData\CData ADO.NET Provider for OData 2021\lib\netstandard2.1\EFCORE50\CData.EntityFrameworkCore.OData.dll</HintPath>
</Reference>
<Reference Include="System.Data.CData.OData">
<HintPath>C:\Program Files\CData\CData ADO.NET Provider for OData 2021\lib\netstandard2.0\System.Data.CData.OData.dll</HintPath>
</Reference>
Start Gain, make sure OData endpoint is enabled.
Scaffold-DbContext "URL=http://localhost:8000/odata;" CData.EntityFrameworkCore.OData -OutputDir Models -Context ODataContext -Tables Event,Exchange,Holding,Institution,Instrument,Price -Force
- Click on Add Connection
- Select Entity Framework Core (2.x, 3.x, 5.x)
- In the resulting dialog, select the project dll and then the DbContext class.
Add the Connection String as a user secret to the project. Due to a bug, the secret cannot be accessed when the context is used in LinqPad. To work around this problem, add these lines to ODataContext.cs:
public ODataContext(string connectionString) : base(GetOptions(connectionString))
{
}
private static DbContextOptions GetOptions(string connectionString)
{
return new DbContextOptionsBuilder().UseOData(connectionString).Options;
}
Then use the third option when adding the EF DbConnection ("Via a constructor that accepts a string"), enter the connection string and check the Encrypt checkbox.
- Right-click on Controllers folder and click Add -> Controller...
- Choose MVC Controller with views using EF
- Select Model class <Model Name> and context ODataContext
- Click Add
- Run App
- Navigate to /<Model Name> endpoint