entity-framework-core

Identity dbcontext reference to another dbcontext

折月煮酒 提交于 2019-12-13 02:48:44
问题 I have two db contexts in my project. One for users based .Net core identity and another for products and orders etc. for a webshop. The scenario is that a user via .Net core identity can log in, add product to shopping cart and complete an order. Therefor a need to have a foreign key from the identity user dbcontext to the other dbcontext containing the orders and product tables. I would like to have the users and the products/orders in two seperate dbcontext. So my question is how to go

EF Core Fluent API Configuration Prevents TPC Inheritance

南楼画角 提交于 2019-12-13 02:35:02
问题 I have models which inherit from each other, but I am struggling to get the fluent api configuration to behave as I want it to. Let's say I have a base class which defines some core properties public class Entity { public int Id { get; set; } public string Title { get; set }; } And a subclass for Book public class Book : Entity { public int Edition { get; set; } } This way I can have books, magazines, pamphlets, comics, speeches etc, all inheriting from my Entity, and not have to define the

Trying to implement a LeftJoin extension method to work with EF Core 2.0

别来无恙 提交于 2019-12-13 00:44:32
问题 I am trying to have an extension method to implement left outer join which returns IQueryable that run against EF Core 2.0 data context. I read the Stack Overflow thread here for help: Extension method for IQueryable left outer join using LINQ. The accepted answer had some problems that were addressed in a later answer here by Jan Van der Haegen. I attempted to use the LeftJoin extension method described there with an EF Core 2.0 data context and ran into an exception which I cannot seem to

Entity Framework Core: Multiple Relationships between Users and Organizations

空扰寡人 提交于 2019-12-13 00:44:29
问题 I have 2 model classes for Users and Organizations. public class User : IdentityUser { [Required] public string Name { get; set; } [Required] public string Surname { get; set; } public int? OrganizationID { get; set; } public virtual OrgList org { get; set; } } public class OrgList { public OrgList() { employees = new HashSet<User>(); } public int id { get; set; } public String name { get; set; } public String ownerId { get; set; } public virtual ICollection<User> employees { get; set; }

EF Core Include multiple inherited types TPH

依然范特西╮ 提交于 2019-12-13 00:14:39
问题 The problem Query BaseClass and Include information from derived types. For example: Base class Offer has two types one with a Card only ( CardOffer ) and with Multiple Cards ( CarouselOffer ). Question: How to query the BaseClass and Include the information from the derived types CardOffer and CarouselOffer? In the manner shown below: _dbContext.Offers.Include(...).ToList(); Currently I solved this by querying each inherited type var cards = await _dbContext.CardOffers .Include(c => c.Card)

AutoMapper don't work with entity EF Core

落爺英雄遲暮 提交于 2019-12-12 23:38:50
问题 I'm trying to get view from entity with fields that I specify at expandProperties with .ProjectTo(). Using .Net Core 2 + Ef Core + AutoMapper There is entities: public class LessonCatalog { public string Name { get; set; } public int? ImageId { get; set; } public virtual Image Image { get; set; } public virtual ICollection<Lesson> Lessons { get; set; } } public class Lesson { public string Name { get; set; } public string Description { get; set; } public int? ImageId { get; set; } public

ASP.NET 5 multiple dbcontext problems

懵懂的女人 提交于 2019-12-12 18:03:40
问题 I'm playing around with the new ASP.NET 5 beta 8 and having trouble when I have two dbcontext. I have the following project structure. -Data(Identity 3 db with other entities) -Resources (Contains a db with translations) -WebApp Stripped away some code in Startup.cs in WebApp public void ConfigureServices(IServiceCollection services) { services.AddEntityFramework() .AddSqlServer() .AddDbContext<DatabaseContext>(opt => opt.UseSqlServer(Configuration["Data:MainDb:ConnectionString"])); services

Xamarin Forms +Entity Framework Core + SQLite - Calling migration on production breaks application

百般思念 提交于 2019-12-12 17:19:52
问题 First I run the following setup Xamarin Forms - Entity Framework Core 2.2 - SQLite - Android - DEBUG And everything works fine. The .db file is generated properly and queries are executed on the database. Then I prepared the application for production and I changed the DEBUG to RELEASE compiled, and packed into an apk. As installed on the device the application always crashes when calling either Database.Migrate() or Database.EnsureCreated() The scenario is the same on every application I

How do I convert complex T-SQL into Linq

痴心易碎 提交于 2019-12-12 17:01:32
问题 I am working in an Asp.NET Core 2.0 project, using EntityFramework Core 2.0. I am trying to convert an existing legacy SQL stored procedures into Linq in EntityFramework Core and I am having difficulty with this particular segment of T-SQL; SET @Target = (SELECT MIN(A.[Serial]) FROM (SELECT [HighSerial] + 1 AS 'Serial' FROM [Efn] WHERE [Mid] = @Mid AND ([HighSerial] + 1) BETWEEN @MinSerial AND @MaxSerial AND ([HighSerial] + 1) NOT IN (SELECT [LowSerial] FROM [Efn] WHERE [Mid] = @Mid)) A) I

Replicate Entire Row In Entity Framework Core

断了今生、忘了曾经 提交于 2019-12-12 16:06:50
问题 I am trying to retrieve a row from database , changing certain columns value in it and adding it as new row (Entity Framework Core), But it is giving me error Cannot insert explicit value for identity column in table 'Audit_Schedules' when IDENTITY_INSERT is set to OFF. This table have a Primary Key "ScheduleId" Below is my Code AuditSchedules _schedules = new AuditSchedules(); using (var ctx = new QuestionnaireEntities(_configuration)) { _schedules = ctx.AuditSchedules.Where(x => x