entity-framework

Entity Framework - check whether has grandchild records

大兔子大兔子 提交于 2021-01-29 11:30:21
问题 I am using asp net core 2.0 and entity framework to access a MySQL database. My model structure looks like public class Parent { [Key] public int Id { get; set; } public virtual ICollection<Child> Child { get; set; } [NotMapped] public virtual bool HasGrandchild { get; set; } } public class Child { [Key] public int Id { get; set; } public int ParentId { get; set; } public virtual ICollection<Grandchild> Grandchild { get; set; } } public class Grandchild { [Key] public int Id { get; set; }

Distinct Column in SelectList for dropdown list

和自甴很熟 提交于 2021-01-29 11:29:35
问题 I am retrieving distinct values from a table against only one column. when I debug ViewData in controller it has retrieved the values perfectly, but in my view it says Object is not referenced. can some one help me out. I think the dataValueField and dataTextField are not named "TeamName" anymore after distinct is applied. how to name selected column of my choice so that below SelectList could work. thanks Controller ViewData["TeamNames"] = new SelectList(_context.ActivityMaps.Select(s => s

Is a DbSet required to run a stored procedure?

南楼画角 提交于 2021-01-29 11:06:05
问题 I have a stored procedure that returns data from a multi-table query. To do this do I need to create a DbSet for each of the tables that are involved in the query? All the examples I find that use FromSql have a DbSet (e.g., Books in the below example) specified before the FromSql clause. using (var context = new SampleContext()) { var books = context.Books .FromSql("EXEC GetAllBooks") .ToList(); } My understanding is a DbSet represents an table. Note that I am working against an existing DB

Can ODP.NET support LDAP with the Entity Frameworks tools?

断了今生、忘了曾经 提交于 2021-01-29 10:12:35
问题 Does anyone know if ODP.NET Managed Access (Oracle.ManagedDataAccess 12.2) support LDAP with the Entity Frameworks tools (vs 2017 Entity Framework 6.2)? The DBA inhibited access through TNS, so I no longer unable to connect to database to update the data models. The error message I received was ORA-12154 TNS could not resolve the connect identifier specified. I tried to include the LDAPSetting in the app.net, but that didn't work. Is there any way I could still use the Entity Framework tools

asp.net mvc multitenant database per tenant

末鹿安然 提交于 2021-01-29 10:05:15
问题 I'm building an app for our company which needs to have separate database per client. App is for the usage of other multiple companies, so the app needs to identify the company name when the user logs in and make the users operate only within their company db. I have it all set, but the problem is that the app is not able to handle 2 different databases simultaneously. When users from two different companies log in, the first users db gets changed to the db of the second user who is logged in

ef core 3.0 query with join table from DB and list from memory fails

一笑奈何 提交于 2021-01-29 10:00:35
问题 I wrote simple query, which should find images with hashes already presented in database. So "images" is List from memory and _context.AdPics is table from DB var picsThatAlreadyInDb = (from pic in _context.AdPics join image in images on pic.ImgHash equals image.ImgHash select new {DbPicId=pic.ID, newImage = image}).ToList(); I get this error: System.InvalidOperationException : Processing of the LINQ expression 'DbSet<AdPic> .Join( outer: __p_0, inner: pic => pic.ImgHash, outerKeySelector:

The entity type 'AspNetUserLogins' requires a primary key to be defined?

蹲街弑〆低调 提交于 2021-01-29 09:04:40
问题 I scaffolded my database with EF and I changed the mydbcontext to inherit from IdentityDbContext because I want everything under one dbcontext . The problem is that when I start the application and write the credentials in the login page, I get an exception: The entity type 'AspNetUserLogins' requires a primary key to be defined which I didn't get before, because I am calling the base.OnModelCreating(modelBuilder); What am I doing wrong? public partial class AdventuresContext :

Impersonation Middleware in an Asp.Net Core Intranet app for Windows-Identity

故事扮演 提交于 2021-01-29 08:08:47
问题 Before I explain my problem, here's our scenario: Scenario We write software only for our intranet Windows users (currently managed by local Active Directory but in future it is possible we migrate to Azure-AD). Up to yet there is an old monolithic Winforms app which communicates directly with the database using datasets. All requests to the database happens with WindowsIdentity (end-user context), so the database knows the end user. For future development we want to use a Web API for

How to have two self-references in an entity class

為{幸葍}努か 提交于 2021-01-29 07:25:21
问题 I have a Foo that can have two optional references to itself: ParentId and RootId . public class Foo { [Key] public int FooId { get; set; } public int? ParentId { get; set; } [ForeignKey(nameof(ParentId))] public virtual Foo Parent { get; set; } public int? RootId { get; set; } [ForeignKey(nameof(RootId))] public virtual Foo RootFoo { get; set; } // ... } Having one works fine, but when I introduce the second self-reference I get error: Unable to determine the principal end of an association

Entity Framework not showing up in Rider on Mac

萝らか妹 提交于 2021-01-29 07:01:01
问题 So I am just starting to learn Asp.Net and am using Rider on Mac as my IDE. I'm am trying to enable migrations, however, I don't see Entity Frameworks option in tools under project context menu. Below is the link to the image: I was wondering if any of you have encountered this issue? If so, what did you do to fix it? 回答1: According to your screenshot, you've installed core EF NuGet. But your project is a classic one. Please, try installing the standard EntityFramework NuGet package. Also,