https://github.com/stofte/roslyn-ef-codegen
dynamic compile example of ef7 code using roslyn
https://github.com/stofte/roslyn-ef-codegen
Last synced: about 1 year ago
JSON representation
dynamic compile example of ef7 code using roslyn
- Host: GitHub
- URL: https://github.com/stofte/roslyn-ef-codegen
- Owner: stofte
- Created: 2016-05-03T20:36:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-17T13:08:54.000Z (over 9 years ago)
- Last Synced: 2025-02-01T02:18:44.308Z (over 1 year ago)
- Language: C#
- Size: 397 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Microsoft.CodeAnalysis/EntityFrameworkCore codegeneration example
-----------------------------------------------------------------
[](https://ci.appveyor.com/project/stofte/roslyn-ef-codegen) [](https://travis-ci.org/stofte/roslyn-ef-codegen)
This repository contains some rough POC code that
shows how to use CodeAnalysis and EFCore to create dynamic
queries at runtime against databases chosen at runtime.
.NET Core 1.1 is required to run the code.
The code is linear and starts in `Program.Main`:
- Generate a SQLite schema/context in-memory using EF's reverse engineering tools
- Use CodeAnalysis to compile and load the schema
- Compile a query `SomeNs.Generated : IGenerated` and link the EF context
- Create an instance of the generated query and calls its main method
- The instance first calls back to the host library (to test that "static" host classes can be referenced)
- It then creates an instance of the EF context, and counts the number of city names starting with "Ca"
The Xunit test project just calls the main projects `Main` method (mostly to test that everything connects).
Usage
-----
dotnet restore
dotnet test test/ConsoleApp.Test
Output should be
Serious testing:
hello from main
Cities starting with 'Ca': 83