-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify to fix issue for #2076, Containment expand problem #2083
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,9 @@ | |
|
||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace AspNetCore3xEndpointSample.Web.Models | ||
{ | ||
{/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this commented out? Is it no longer used? Just remove? |
||
public class Customer | ||
{ | ||
public int Id { get; set; } | ||
|
@@ -35,5 +34,5 @@ public class Address | |
public string City { get; set; } | ||
|
||
public string Street { get; set; } | ||
} | ||
}*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
//using Microsoft.EntityFrameworkCore; | ||
|
||
using System.Data.Entity; | ||
|
||
namespace AspNetCore3xEndpointSample.Web.Models | ||
{ | ||
public class CustomerOrderContext : DbContext | ||
{ | ||
public CustomerOrderContext(DbContextOptions<CustomerOrderContext> options) | ||
: base(options) | ||
//public CustomerOrderContext(DbContextOptions<CustomerOrderContext> options) | ||
// : base(options) | ||
//{ | ||
//} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be removed? |
||
|
||
public CustomerOrderContext(string connectString) | ||
: base(connectString) | ||
{ | ||
} | ||
|
||
public DbSet<Customer> Customers { get; set; } | ||
|
||
public DbSet<Order> Orders { get; set; } | ||
// public DbSet<Order> Orders { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? |
||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
protected override void OnModelCreating(DbModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Customer>().OwnsOne(c => c.HomeAddress).WithOwner(); | ||
modelBuilder.Entity<CustomerPhone>().HasOptional(a => a.Formatted).WithRequired(); | ||
modelBuilder.Entity<Customer>() | ||
.HasMany(c => c.CustomerReferrals) | ||
.WithRequired(c => c.Customer) | ||
.HasForeignKey(c => c.CustomerID); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
|
||
using Microsoft.AspNet.OData.Builder; | ||
using Microsoft.OData.Edm; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace AspNetCore3xEndpointSample.Web.Models | ||
{ | ||
|
@@ -15,13 +18,64 @@ public static IEdmModel GetEdmModel() | |
if (_edmModel == null) | ||
{ | ||
var builder = new ODataConventionModelBuilder(); | ||
builder.EntitySet<Customer>("Customers"); | ||
builder.EntitySet<Order>("Orders"); | ||
var customers = builder.EntitySet<Customer>("Customers"); | ||
customers.Binding.HasManyPath(c => c.CustomerReferrals, true).HasRequiredBinding(r => r.ReferredCustomer, "Customers"); | ||
// builder.EntitySet<Order>("Orders"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? |
||
_edmModel = builder.GetEdmModel(); | ||
} | ||
|
||
return _edmModel; | ||
} | ||
|
||
} | ||
|
||
public class Customer | ||
{ | ||
[Key] | ||
public int ID { get; set; } | ||
|
||
[Contained] | ||
public virtual ICollection<CustomerReferral> CustomerReferrals { get; set; } | ||
|
||
[Contained] | ||
public virtual ICollection<CustomerPhone> Phones { get; set; } | ||
} | ||
|
||
public class CustomerReferral | ||
{ | ||
[Key] | ||
public int ID { get; set; } | ||
|
||
public int CustomerID { get; set; } | ||
|
||
public int ReferredCustomerID { get; set; } | ||
|
||
[Required] | ||
[ForeignKey(nameof(CustomerID))] | ||
public virtual Customer Customer { get; set; } | ||
|
||
[Required] | ||
[ForeignKey(nameof(ReferredCustomerID))] | ||
public virtual Customer ReferredCustomer { get; set; } | ||
} | ||
|
||
public class CustomerPhone | ||
{ | ||
[Key] | ||
public int ID { get; set; } | ||
|
||
[Editable(false)] | ||
public int CustomerID { get; set; } | ||
|
||
[Contained] | ||
public virtual CustomerPhoneNumberFormatted Formatted { get; set; } | ||
} | ||
|
||
public class CustomerPhoneNumberFormatted | ||
{ | ||
[Key] | ||
public int CustomerPhoneNumberID { get; set; } | ||
|
||
public string FormattedNumber { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using AspNetCore3xEndpointSample.Web.Models; | ||
using Microsoft.AspNet.OData.Batch; | ||
using Microsoft.AspNet.OData.Extensions; | ||
|
@@ -11,12 +9,13 @@ | |
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.OData; | ||
using Microsoft.OData.Edm; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AspNetCore3xEndpointSample.Web | ||
{ | ||
|
@@ -32,7 +31,8 @@ public Startup(IConfiguration configuration) | |
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDbContext<CustomerOrderContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("CustomerOrderList")); | ||
//services.AddDbContext<CustomerOrderContext>(opt => opt.UseLazyLoadingProxies().UseInMemoryDatabase("CustomerOrderList")); | ||
//services.AddScoped<CustomerOrderContext>(_ => new CustomerOrderContext(Configuration.GetConnectionString("DefaultConnection"))); | ||
services.AddOData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented out lines? |
||
services.AddRouting(); | ||
} | ||
|
@@ -54,6 +54,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.Expand(); | ||
endpoints.MapODataRoute( | ||
"nullPrefix", null, | ||
b => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to keep the commented out version?