Giter Site home page Giter Site logo

odatademo's Introduction

CData OData connector with LinqPad 6

Instruction for Using CData Connector

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

Required Packages

Microsoft

Install-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.Relational
Install-Package Microsoft.EntityFrameworkCore.Tools

CData Assemblies (check the hint path on your installation)

  <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>

Scaffolding Model Classes

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

LinqPad Integration

Using the auto-generated ODataContext class with hard-coded Connection String

  1. Click on Add Connection
  2. Select Entity Framework Core (2.x, 3.x, 5.x)
  3. In the resulting dialog, select the project dll and then the DbContext class.

Hiding the Connection String

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.

Scaffold Controller Code

  1. Right-click on Controllers folder and click Add -> Controller...
  2. Choose MVC Controller with views using EF
  3. Select Model class <Model Name> and context ODataContext
  4. Click Add
  5. Run App
  6. Navigate to /<Model Name> endpoint

odatademo's People

Contributors

monte-christo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.