Skip to content

Instantly share code, notes, and snippets.

View xuzhg's full-sized avatar
🏠
Working from home

Sam Xu xuzhg

🏠
Working from home
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="ODataApiVersion.Models.v1" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Customer">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Name" Type="Edm.String" />
<Property Name="PhoneNumber" Type="Edm.String" />
{
"@odata.context":"http://localhost:5001/odata/$metadata#Books(ISBN,Location,Press(Name))",
"value":[
{
"ISBN":"063-6-920-02371-5",
"Location":{
"Street":"Main ST"
},
"Press":{
"Name":"O'Reilly"
{
"@odata.context":"http://localhost:5001/odata/$metadata#Books/$entity",
"Id":2,
"ISBN":"063-6-920-02371-5",
"Title":"Enterprise Games",
"Author":"Michael Hugos",
"Price":49.99,
"Location":{
"City":"Bellevue",
"Street":"Main ST"
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BookStoreContext>(opt => opt.UseInMemoryDatabase("BookLists"));
services.AddControllers();
services.AddOData();
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.0-beta" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0-preview.2.20159.4" />
</ItemGroup>
@xuzhg
xuzhg / bookstore.csproj
Created July 3, 2018 23:01
bookstore.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
@xuzhg
xuzhg / BookStoreContext.cs
Last active November 28, 2019 13:35
BookStoreContext.cs
public class BookStoreContext : DbContext
{
public BookStoreContext(DbContextOptions<BookStoreContext> options)
: base(options)
{
}
public DbSet<Book> Books { get; set; }
public DbSet<Press> Presses { get; set; }
@xuzhg
xuzhg / ConfigureServicesDb.cs
Created July 3, 2018 22:58
ConfigureServicesDb.cs
public class Startup
{
// ...
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BookStoreContext>(opt => opt.UseInMemoryDatabase("BookLists"));
services.AddOData();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
}
@xuzhg
xuzhg / DataSource.cs
Created July 3, 2018 22:57
DataSource.cs
public static class DataSource
{
private static IList<Book> _books { get; set; }
public static IList<Book> GetBooks()
{
if (_books != null)
{
return _books;
}