entity-framework-core

EF7 nested Include not showing in Razor .net

大兔子大兔子 提交于 2020-01-06 13:11:34
问题 I have my models like this: Goup.cs GroupUser (pivot table) ApplicationUser (User) -> 4. Profile And now I want to show the data in Profile on a details page when the User belongs to the group. I'm doing this like this: private IEnumerable<GroupUser> GetUsers(int groupId) { IEnumerable<GroupUser> model = null; if(groupId == 0) { model = _kletsContext.GroupUser.OrderByDescending(o => o.GroupId).AsEnumerable(); } else { model = _kletsContext.GroupUser.Where(g => g.GroupId == groupId).Include(p

EF7 nested Include not showing in Razor .net

不羁岁月 提交于 2020-01-06 13:10:43
问题 I have my models like this: Goup.cs GroupUser (pivot table) ApplicationUser (User) -> 4. Profile And now I want to show the data in Profile on a details page when the User belongs to the group. I'm doing this like this: private IEnumerable<GroupUser> GetUsers(int groupId) { IEnumerable<GroupUser> model = null; if(groupId == 0) { model = _kletsContext.GroupUser.OrderByDescending(o => o.GroupId).AsEnumerable(); } else { model = _kletsContext.GroupUser.Where(g => g.GroupId == groupId).Include(p

A network-related or instance-specific error occurred while establishing a connection to SQL Server while migration with asp.net core migration

被刻印的时光 ゝ 提交于 2020-01-06 06:09:07
问题 I, am using package manager console to perform the database migration. I used the following command Add-Migration init This command work perfectly and created the migration object as see in the below image Now I am using Update-Database command to create the database however I, am getting an error as shown below I have used the solution provide here and this question. However, this solution is not working for me from visual studio. I, am able to use the sql server from SSMS. This error is

Entity Framework generic entity inheritance id error

旧城冷巷雨未停 提交于 2020-01-06 05:08:32
问题 Part 2 problem, which continues from here: EntityFramework Core - Update record fails with DbUpdateConcurrencyException Error: The derived type 'BinaryFile' cannot have KeyAttribute on property 'Id' since primary key can only be declared on the root type. I am trying to make inheritance for my entities as much as possible, so I remove duplication as much as possible. My inheritance structure: public interface IEntityMinimum { bool IsDeleted { get; set; } byte[] Version { get; set; } string

How to avoid circular navigation properties in Entity Framework Core?

谁说我不能喝 提交于 2020-01-06 03:42:46
问题 I have a such table schema: CREATE TABLE Categories ( Id INT IDENTITY(1,1), Name varchar(100), CONSTRAINT PK_Category_Id PRIMARY KEY (Id) ) CREATE TABLE Products ( Id INT IDENTITY(1,1), IdCategory INT NOT NULL CONSTRAINT FK_Products_IdCategory__Categories_Id FOREIGN KEY(IdCategory) REFERENCES Categories(Id), Name varchar(100), Price decimal(18,2), ImageUrl varchar(256), CONSTRAINT PK_Product_Id PRIMARY KEY (Id) ) EF Core generated the following code: public partial class Categories { public

How to configure this one-to-zero-or-one relationship?

给你一囗甜甜゛ 提交于 2020-01-06 03:11:25
问题 I know there are some answered questions on SO about 1:0..1-relationships. I have looked at this and this, but don't think they apply to my question. I have these three (simplified) models in a CMS-system. public class FrontPageItem { public int Id { get; set; } public int ItemType { get; set; } // 1 = Article, 2 = WebPage, etc... public int? ArticleId { get; set; } public Article Article { get; set; } public int? WebPageId { get; set; } public WebPage WebPage { get; set; } } public class

Create relationship with a property inside owned Entity causes an error

强颜欢笑 提交于 2020-01-05 08:54:14
问题 I have an entity that has owned type and i want to create relationship with another entity but the foreign key property exist on the owned type example:- This is my employee entity public sealed class Employee : AuditedAggregateRoot { public WorkInformation WorkInformation { get; private set; } } and it contains a value Object(Owned Type) called WorkInformation public class WorkInformation : ValueObject<WorkInformation> { private WorkInformation() { } public int? DepartmentId { get; private

.NET Core Npgsql.EntityFrameworkCore ILikeExpression

﹥>﹥吖頭↗ 提交于 2020-01-05 08:37:28
问题 I am using EntityFramework Core with Npgsql provider, perform ILIKE query works fine: var query = dbContext.countries .Where(w => (w.name != null && EF.Functions.ILike(w.name, $"{search}%") ); Query is translated into PostgreSQL's ILIKE, so far so good. I am also building a dynamic LINQ based on annotation - [Searchable] or [Orderable] properties in models - and I am trying to find out how to perform ILIKE using Expressions and Lambda. Code: // works, except it produces just LIKE which is

How do I target another database with Audit.Net - Audit.EntityFramework.Core

坚强是说给别人听的谎言 提交于 2020-01-05 07:55:08
问题 I'm trying to implement the Audit.EntityFramework.Core package from the Audit.Net repository but am running into some difficulty. I'm unable to save changes or target a different database. I've modified my SaveChanges and SaveChangesAsync function to call the Audit.Net DbContextHelper class's save functions but I'm missing something. Is there a way to do the following? Target another database for storing audit data using an audit DbContext that inherits from the DbContext I'm trying to audit?

Stop EF Core from using Merge to Insert

五迷三道 提交于 2020-01-05 07:16:43
问题 I am converting my application to .NET Core. In doing so, I am running into issues with EF Core and inserts. If I insert 1 or 2 rows then EF Core performs a normal SQL INSERT statement. But when I have 3 or more rows, it switches to a MERGE statement, which then fails with: The column reference "inserted.MyKeyColumn" is not allowed because it refers to a base table that is not being modified in this statement. My guess is that this is due to the fact that the query is actually running on a