EF Core mapping wrong property name - c#

This is my first web application using ASP.NET Core 5+.
Please consider the following fluent chains:
modelBuilder.Entity<Category>().ToTable("Category");
modelBuilder.Entity<Item>().ToTable("Item");
modelBuilder.Entity<ItemCode>().ToTable("ItemCode");
modelBuilder.Entity<ItemType>().ToTable("ItemType");
modelBuilder.Entity<Customer>().ToTable("Customer");
modelBuilder.Entity<OrderStatus>().ToTable("OrderStatus");
modelBuilder.Entity<Order>().ToTable("Order");
modelBuilder.Entity<OrderItem>().ToTable("OrderItem");
modelBuilder.Entity<OrderTax>().ToTable("OrderTax");
modelBuilder.Entity<Item>()
.HasOne<Category>(s => s.Category)
.WithMany(c => c.Items)
.HasForeignKey(p => p.CategoryName)
.HasPrincipalKey(c => c.Name).IsRequired();
modelBuilder.Entity<Item>()
.HasOne(s => s.ItemType)
.WithMany(c => c.Items)
.HasForeignKey(p => p.ItemTypeName)
.HasPrincipalKey(c => c.Name).IsRequired();
modelBuilder.Entity<Item>()
.HasOne(s => s.ItemCode)
.WithMany(c => c.Items)
.HasForeignKey(p => p.ItemCodeName)
.HasPrincipalKey(c => c.Name).IsRequired();
modelBuilder.Entity<Order>()
.HasOne(s => s.OrderStatus)
.WithMany(c => c.Orders)
.HasForeignKey(p => p.OrderStatusName)
.HasPrincipalKey(c => c.Name).IsRequired();
modelBuilder.Entity<Order>()
.HasOne(s => s.Customer)
.WithMany(c => c.OrdersCustomer)
.HasForeignKey(p => p.CustomerName)
.HasPrincipalKey(c => c.Name).IsRequired();
modelBuilder.Entity<OrderItem>()
.HasOne<Order>(s => s.Order)
.WithMany(c => c.OrderItemsOrders)
.HasForeignKey(p => p.Name)
.HasPrincipalKey(c => c.Name)
.IsRequired();
modelBuilder.Entity<OrderItem>()
.HasOne<Item>(s => s.Item)
.WithMany(c => c.OrderItems)
.HasForeignKey(p => p.ItemName)
.HasPrincipalKey(c => c.Name)
.IsRequired();
modelBuilder.Entity<OrderTax>()
.HasOne<Order>(s => s.Order)
.WithMany(c => c.OrderTaxesOrders)
.HasForeignKey(p => p.OrderName)
.HasPrincipalKey(c => c.Name)
.IsRequired();
but the EF mapping for Pages\OrderItems\Create.cshtml.cs is: (generated automatically)
ViewData["ItemName"] = new SelectList(_context.Items, "Name", "CategoryName");
ViewData["Name"] = new SelectList(_context.Orders, "Name", "CustomerName");
return Page();
where as this should be:
ViewData["ItemName"] = new SelectList(_context.Items, "Name", "ItemName");
ViewData["Name"] = new SelectList(_context.Orders, "Name", "OrderName");
return Page();
The model classes are:
public class OrderItem
{
public int OrderItemID { get; set; }
public string Name { get; set; }
public Order Order { get; set; }
public string ItemName { get; set; }
public Item Item { get; set; }
public int Quantity { get; set; }
}
public class OrderTax
{
public int OrderTaxID { get; set; }
[Required] public string Name { get; set; }
public int Percentage { get; set; }
public string OrderName { get; set; }
public Order Order { get; set; }
}
and in Item model class I have public List<OrderItem> OrderItems { get; set; }.
and in the Order class I have public List<OrderItem> OrderItemsOrders { get; set; } and public List<OrderTax> OrderTaxesOrders { get; set; }
all the other models and mappings are working as expected, I'm having bad time making this work.
PS: I can edit the needed mappings manually by editing the files, but as per ef this should be automatically mapped.
I'm aware that I'm doing something wrong, but haven;t found anything related to this while googling.
Any help & suggestions are welcome, thanks in advance.

Related

Error: Failed executing DbCommand cannot execute insert command

I'm trying to add an entity to one of my tables but an error occurred. You can find below model, controller and output debug:
noting that I'm using this approach in my entire project and there is no problem, i don't know why he called the applicationUserId it's not in the related model...
model:
public class Rate
{
public int Id { get; set; }
public int ProjectId { get; set; }
[ForeignKey("ProjectId")]
public Projects Project { get; set; }
}
Controller:
var rate = new Rate
{
ProjectId = CPVM.Id,
};
rateRepository.Add(rate);
Rep:
public void Add(Rate entity)
{
db.Rate.Add(entity);
db.SaveChanges();
}
debugger output:
Microsoft.EntityFrameworkCore.Database.Command: Error: Failed executing DbCommand (2ms) [Parameters=[#p0='?' (Size = 450), #p1='?' (DbType = Int32), CommandType='Text', CommandTimeout='30']
INSERT INTO [Rate] ([ApplicationUserId], [ProjectId])
VALUES (#p0, #p1);
DBContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>().ToTable("Users");
builder.Entity<IdentityRole>().ToTable("Roles");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaims");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRoles");
builder.Entity<IdentityUserLogin<string>>().ToTable("Userlogins");
builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaims");
builder.Entity<IdentityUserToken<string>>().ToTable("UserTokens");
builder.Entity<Bids>()
.HasKey(b => b.Id);
builder.Entity<Languages>()
.HasKey(l => l.Id);
builder.Entity<Rate>()
.HasKey(r => r.Id);
builder.Entity<Projects>()
.HasKey(p => p.Id);
builder.Entity<TranslatorsLanguages>()
.HasKey(t => t.Id);
builder.Entity<TranslatorsLanguages>()
.HasOne(p => p.Languages)
.WithMany(b => b.TranslatorsLanguagesList)
.HasForeignKey(b => b.FromLanguage);
builder.Entity<TranslatorsLanguages>()
.HasOne(p => p.Languages)
.WithMany(b => b.TranslatorsLanguagesList)
.HasForeignKey(b => b.ToLanguage);
builder.Entity<TranslatorsLanguages>()
.HasOne(p => p.ApplicationUser)
.WithMany(b => b.TranslatorLanguagesList)
.HasForeignKey(b => b.TranslatorId);
builder.Entity<Projects>()
.HasOne(p => p.ApplicationUser)
.WithMany(b => b.ProjectsList)
.HasForeignKey(b => b.CustomerId);
builder.Entity<Projects>()
.HasOne(p => p.Languages)
.WithMany(b => b.ProjectsList)
.HasForeignKey(b => b.FromLanguage);
builder.Entity<Projects>()
.HasOne(p => p.Languages)
.WithMany(b => b.ProjectsList)
.HasForeignKey(b => b.ToLanguage);
builder.Entity<Bids>()
.HasOne(p => p.ApplicationUser)
.WithMany(b => b.BidsList)
.HasForeignKey(b => b.TranslatorId);
builder.Entity<Bids>()
.HasOne(p => p.Projects)
.WithMany(b => b.BidsList)
.HasForeignKey(b => b.ProjectId);
}
public DbSet<Languages> Languages { get; set; }
public DbSet<Projects> Projects { get; set; }
public DbSet<Rate> Rate { get; set; }
public DbSet<TranslatorsLanguages> TranslatorsLanguages { get; set; }
public DbSet<Bids> Bids { get; set; }
}
I found that in the applicationUser model there is a reference for Rate model public List<Rate> RateList { get; set; } when i removed it, it works!!

Many to Many Relationship and the Create View

I have an object (Route) that has 2 properties (Donor and Agency). Both Donor and Agency are both of type Organization. In the database, I have a many to many relationship setup for Route<>Donor and Route<>Agency. When I try to run my code, it tells me that I need to setup a ForeignKey for one of these relationships, but I'm kind of lost at this point. Am I doing this right? What am I missing?
Here is the Route Class...
public partial class Route
{
public Route()
{
RouteOrg = new HashSet<RouteOrg>();
}
public int RouteId { get; set; }
public int RouteOrgId { get; set; }
public virtual ICollection<RouteOrg> RouteOrg { get; set; }
public List<Organization> Donors { get; set; }
public List<Organization> Agencies { get; set; }
}
Here is the Organization Class...
public partial class Organization
{
public Organization()
{
RouteOrgAgency = new HashSet<RouteOrg>();
RouteOrgDonor = new HashSet<RouteOrg>();
}
public int OrgId { get; set; }
public bool IsSelected { get; set; }
public int? RouteId { get; set; }
public virtual ICollection<RouteOrg> RouteOrgAgency { get; set; }
public virtual ICollection<RouteOrg> RouteOrgDonor { get; set; }
}
And here is my OnModelCreating method...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
modelBuilder.Entity<Organization>(entity =>
{
entity.HasKey(e => e.OrgId);
entity.HasIndex(e => e.AddressId);
entity.HasIndex(e => e.OrganizationTypeId);
entity.Property(e => e.OrgId).HasColumnName("OrgId");
entity.Property(e => e.AddressId).HasColumnName("AddressId");
entity.Property(e => e.DateAdded).HasDefaultValueSql("(getutcdate())");
entity.Property(e => e.Name).HasMaxLength(100);
entity.Property(e => e.Nickname).HasMaxLength(50);
entity.Property(e => e.OrganizationTypeId).HasColumnName("OrganizationTypeId");
entity.Property(e => e.UserId)
.HasColumnName("UserId")
.HasMaxLength(450);
});
modelBuilder.Entity<Route>(entity =>
{
entity.HasIndex(e => e.DayOfWeekId);
entity.HasIndex(e => e.FrequencyId);
entity.HasIndex(e => e.TimeOfDayId);
entity.Property(e => e.RouteId).HasColumnName("RouteId");
entity.Property(e => e.DateAdded).HasDefaultValueSql("(getutcdate())");
entity.Property(e => e.DayOfWeekId).HasColumnName("DayOfWeekId");
entity.Property(e => e.FrequencyId).HasColumnName("FrequencyId");
entity.Property(e => e.RouteOrgId).HasColumnName("RouteOrgId");
entity.Property(e => e.TimeOfDayId).HasColumnName("TimeOfDayId");
});
modelBuilder.Entity<RouteOrg>(entity =>
{
entity.Property(e => e.RouteOrgId).HasColumnName("RouteOrgId");
entity.Property(e => e.AgencyId).HasColumnName("AgencyId");
entity.Property(e => e.DonorId).HasColumnName("DonorId");
entity.Property(e => e.RouteId).HasColumnName("RouteId");
entity.HasOne(d => d.Agency)
.WithMany(p => p.RouteOrgAgency)
.HasForeignKey(d => d.AgencyId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_RouteOrg_Agency");
entity.HasOne(d => d.Donor)
.WithMany(p => p.RouteOrgDonor)
.HasForeignKey(d => d.DonorId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_RouteOrg_Donor");
entity.HasOne(d => d.Route)
.WithMany(p => p.RouteOrg)
.HasForeignKey(d => d.RouteId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_RouteOrg_Route");
});
}
I currently have the Create view showing everything correctly. I'm showing the many to many relationship with a list of check boxes for Donors and one for Agencies. I expect to be able to select as many of each of these types of organizations as I want, save it to the DB, and be able to edit, view, etc and keep all of the data.
UPDATE: I'm also getting this error when trying to run the project now...
System.AggregateException: 'One or more errors occurred. (Both relationships between 'Organization' and 'Route.Agencies' and between 'Organization' and 'Route.Donors' could use {'RouteId'} as the foreign key. To resolve this configure the foreign key properties explicitly on at least one of the relationships.)'
If you're using EF Core, note that EF Core won't map a Many-To-Many relationship automatically for you.
Because one Route will have many RouteOrgs (instead of many Donors or Agencies), you shouldn't configure the two Donors and Agencies properties as fields of the table Route.
public partial class Route
{
...
public List<Organization> Donors { get; set; }
public List<Organization> Agencies { get; set; }
}
Or if you like, configure a [NotMapped] Attribute for these two fields:
public partial class Route
{
...
public int? RouteOrgId { get; set; }
public virtual ICollection<RouteOrg> RouteOrg { get; set; }
[NotMapped]
public IEnumerable<Organization> Donors {
get {
return this.RouteOrg.Select(ro => ro.Donor);
}
}
[NotMapped]
public IEnumerable<Organization> Agencies { get{
return this.RouteOrg.Select( ro => ro.Agency);
} }
}
When you want to get the Donors and Agencies of Routes, use Include().ThenInclude() to query as below:
var routes = await _context.Route
.Include(r => r.RouteOrg)
.ThenInclude(ro => ro.Agency)
.Include(r => r.RouteOrg)
.ThenInclude(ro => ro.Donor)
;

One to Zero Relationship not working?

I have been trying to establish an optional One-to-One relationship between 2 entities unsuccessfully. I can do it by creating a Unique Constraint on the RTUDEVICE tables DeviceId, but I am trying to do it the "right way" through the Fluent API
What am I doing wrong?
Relationship Explanation:
One DEVICE record may have one-and-only-one record in the RTUDEVICE table.
ENTITIES:
Below are simplified versions of the actual classes...
public partial class Device
{
public Int Id { get; set; }
public string DeviceName { get; set; }
public virtual RTUDevice RTUDevice { get; set; }
}
public partial class RTUDevice
{
public Int Id { get; set; }
public int DeviceId { get; set; }
public bool IsCRMAlarmDevice { get; set; }
public bool HasCustomRegisters { get; set; }
public bool HasGasQualityRegisters { get; set; }
public bool HistoryVerified { get; set; }
public virtual Device Device { get; set; }
}
MAPPING:
I did many attempts using various online example without success...the failing code is commented-out.
public DeviceMap(DbModelBuilder modelBuilder)
{
ToTable("Device", "dbo")
.HasKey(m => m.Id);
Property(m => m.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.IsRequired();
Property(m => m.DeviceName)
.IsUnicode(false)
.HasMaxLength(100)
.IsRequired()
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UX_Device_AlternateKey") { IsUnique = true }));
//modelBuilder.Entity<RTUDevice>()
// .HasOptional(e => e.Device)
// .WithRequired(e => e.RTUDevice)
// .WillCascadeOnDelete(true);
}
public RTUDeviceMap(DbModelBuilder modelBuilder)
{
ToTable("RTUDevice", "dbo")
.HasKey(m => m.Id);
Property(m => m.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
.IsRequired();
Property(e => e.DeviceId)
.IsRequired();
Property(e => e.IsCRMAlarmDevice )
.IsRequired();
Property(e => e.HasCustomRegisters)
.IsRequired();
Property(e => e.HasGasQualityRegisters)
.IsRequired();
Property(e => e.HistoryVerified)
.IsRequired();
// One-to-Zero-or-One relationship
//modelBuilder.Entity<RTUDevice>()
// .HasOptional(e => e.Device)
// .WithRequired(e => e.RTUDevice)
// .WillCascadeOnDelete(true);
// One-to-Zero-or-One relationship
//modelBuilder.Entity<RTUDevice>()
// .HasRequired(e => e.Device)
// .WithMany()
// .HasForeignKey(c => c.DeviceId)
// .WillCascadeOnDelete(true);
}
You should just use Id as the PK (as well as FK) in RTUDevice entity and get rid of DeviceId. Then define the relationship as follows:
modelBuilder.Entity<Device>()
.HasKey(it => it.Id);
modelBuilder.Entity<RTUDevice>()
.HasKey(it => it.Id);
modelBuilder.Entity<Device>()
.HasOptional(it => it.RTUDevice)
.WithRequired(it => it.Device);
If DeviceId needs to be used explicitly for mapping, use the following:
modelBuilder.Entity<Device>()
.HasOptional(it => it.RTUDevice)
.WithOptionalPrincipal(it => it.Device)
.Map(it => it.MapKey("DeviceId"));

EntityFramework 6 Mysql .NET Connector 6.9.9 code first migrations

I have a solution with 2 projects in it, an asp.net core mvc 1.0.1 and a .NET 4.6.1 class library with EF6 which contains my entities, domain models, abstractions and viewmodels. I have added the class library as a reference in my asp.net core project. I set my class library project as my startup project and enable migrations and even add successfully. But once I do Update-Database, I get an error sequence contains no matching elements. so I switch and create the same project but not split into class library and web project, its now one asp.net mvc5 project and there, I can't even add migrations after enabling migrations. Both counts I added mysql.data.entity 6.9.9 and followed the instructions at mysql itself and other rich instructions on the internet but I still get the same error.
Here is my dbcontext:
public class SchoolDb : IdentityDbContext<ApplicationUser>
{
public static string ConnString { get; set; } =
"Server=localhost; Database=schooldb; Uid=root; Pwd=l1nux43va;";
public SchoolDb() : base("SchoolDb")
{
}
public static SchoolDb Create()
{
return new SchoolDb();
}
public DbSet<Attendance> Attendance { get; set; }
public DbSet<Class> Classes { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<Result> Results { get; set; }
public DbSet<Teacher> Teachers { get; set; }
public DbSet<MedicalHistory> MedicalHistories { get; set; }
public DbSet<School> Schools { get; set; }
public DbSet<Subject> Subjects { get; set; }
public DbSet<Payment> Payments { get; set; }
public DbSet<SchoolSession> Sessions { get; set; }
public DbSet<TermWork> TermWorks { get; set; }
public DbSet<Staff> Staff { get; set; }
public DbSet<ScoreGrade> ScoreGrades { get; set; }
public DbSet<LessonPlan> LessonPlans { get; set; }
public DbSet<Hostel> Hostels { get; set; }
public DbSet<Guardian> Guardians { get; set; }
public DbSet<BehaviourActivity> BehaviourActivities { get; set; }
public DbSet<Rating> Ratings { get; set; }
public DbSet<TermWorkType> TermWorkTypes { get; set; }
public DbSet<EntranceExam> EntranceExam { get; set; }
public DbSet<EntranceExamCandidate> EntranceExamCandidate { get; set; }
public DbSet<EntranceExamSubject> EntranceExamSubject { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
//fluent annotations
modelBuilder.Entity<Attendance>()
.HasMany(a => a.Students);
modelBuilder.Entity<Attendance>()
.HasRequired(a => a.FormTeacher);
modelBuilder.Entity<BehaviourActivity>()
.HasRequired(b => b.Rating)
.WithOptional(r => r.BehaviourActivity);
modelBuilder.Entity<Class>()
.HasRequired(c => c.FormTeacher);
modelBuilder.Entity<Class>()
.HasOptional(c => c.Subjects).WithOptionalPrincipal();
modelBuilder.Entity<Club>()
.HasMany(c => c.Students);
modelBuilder.Entity<EntranceExam>()
.HasMany(e => e.EntranceExamCandidate)
.WithRequired(e => e.EntranceExam).WillCascadeOnDelete(true);
modelBuilder.Entity<EntranceExam>()
.HasMany(e => e.ExamSubjects)
.WithRequired(s => s.EntranceExam);
modelBuilder.Entity<EntranceExamCandidate>()
.HasMany(e => e.ExamSubjects)
.WithRequired(s => s.EntranceExamCandidate);
modelBuilder.Entity<Guardian>()
.HasMany(g => g.Students)
.WithRequired(s => s.Guardian);
modelBuilder.Entity<Hostel>()
.HasMany(h => h.Students);
modelBuilder.Entity<Hostel>()
.HasRequired(h => h.Patron);
modelBuilder.Entity<MedicalHistory>()
.HasMany(m => m.Disabilities)
.WithRequired(d => d.MedicalHistory);
modelBuilder.Entity<MedicalHistory>()
.HasMany(m => m.Illnesses)
.WithRequired(i => i.MedicalHistory);
modelBuilder.Entity<MedicalHistory>()
.HasMany(m => m.Allergies)
.WithRequired(a => a.MedicalHistory);
modelBuilder.Entity<Payment>()
.HasMany(p => p.PaymentTypes);
modelBuilder.Entity<Payment>()
.HasRequired(p => p.SchoolSession);
modelBuilder.Entity<Result>()
.HasRequired(r => r.Student);
modelBuilder.Entity<Result>()
.HasRequired(r => r.SchoolSession);
modelBuilder.Entity<Result>()
.HasRequired(r => r.Subject);
modelBuilder.Entity<School>()
.HasMany(s => s.Students);
modelBuilder.Entity<School>()
.HasMany(s => s.Teachers);
modelBuilder.Entity<School>()
.HasMany(s => s.Staff)
.WithRequired(s => s.School);
modelBuilder.Entity<SchoolSession>()
.HasRequired(ss => ss.School);
modelBuilder.Entity<Student>()
.HasMany(s => s.Payments)
.WithRequired(p => p.Student);
//modelBuilder.Entity<Student>()
// .HasMany(s => s.Subjects)
// .WithMany(s => s.Students)
// .Map(m =>
// {
// m.MapLeftKey("StudentId");
// m.MapRightKey("SubjectId");
// m.ToTable("StudentsSubjects");
// });
modelBuilder.Entity<Student>()
.HasOptional(s => s.MedicalHistory)
.WithRequired(m => m.Student);
modelBuilder.Entity<Student>()
.HasRequired(s => s.Class);
modelBuilder.Entity<Subject>()
.HasOptional(s => s.ScoreGrade)
.WithOptionalPrincipal(sg => sg.Subject);
modelBuilder.Entity<Teacher>()
.HasMany(t => t.LessonPlans)
.WithRequired(l => l.Teacher);
//modelBuilder.Entity<Teacher>()
// .HasMany(t => t.Subjects)
// .WithMany(s => s.Teachers)
// .Map(m =>
// {
// m.MapLeftKey("TeacherId");
// m.MapRightKey("SubjectId");
// m.ToTable("TeachersSubjects");
// });
modelBuilder.Entity<TermWork>()
.HasRequired(t => t.Student);
modelBuilder.Entity<TermWork>()
.HasRequired(t => t.SchoolSession);
modelBuilder.Entity<TermWork>()
.HasRequired(t => t.Subject);
modelBuilder.Entity<TermWork>()
.HasRequired(t => t.TermWorkType)
.WithOptional(tt => tt.TermWork);
}
}
can anyone guide me on what I need to do to fix this error!?

system.reflection.ambiguousmatchexception error EF

I have a strange situation. This part of code:
List<Order> orders = orderRepository.Query().Where(x => x.del != true).ToList();
Returns an error:
System.Reflection.AmbiguousMatchException- Ambiguous match found.
What is more - without that code below, everything works fine.
How to resolve it? Why I get that error?
Order.cs:
public partial class Order
{
(..)
public virtual Country UserCountry { get; set; }
public virtual Country CompanyCountry { get; set; }
public virtual DeliveryType UserDeliveryType { get; set; }
public virtual PaymentType UserPaymentType { get; set; }
//without that virtual properties everything works fine
}
MyContext.cs:
modelBuilder.Entity<Order>()
.HasRequired(u => u.UserCountry)
.WithMany()
.HasForeignKey(u => u.CountryID).WillCascadeOnDelete(false);
modelBuilder.Entity<Order>()
.HasRequired(u => u.CompanyCountry)
.WithMany()
.HasForeignKey(u => u.companyCountry).WillCascadeOnDelete(false);
modelBuilder.Entity<Order>()
.HasRequired(u => u.UserDeliveryType)
.WithMany()
.HasForeignKey(u => u.DeliveryTypeID).WillCascadeOnDelete(false);
modelBuilder.Entity<Order>()
.HasRequired(u => u.UserPaymentType)
.WithMany()
.HasForeignKey(u => u.PaymentTypeID).WillCascadeOnDelete(false);
//and without that part of code

Categories

Resources