entity-framework

EF Core Query Many to Many with filtering

∥☆過路亽.° 提交于 2021-02-05 09:31:30
问题 I have the following table structure: I want to retrieve all funds for provided reportId . I did it this way: var result = _context.FundsInReports .Join(_context.Funds, a=> a.FundId, b => b.Id, (fir, fund) => new {fir, fund}) .Join(_context.Reports, a=> a.fir.ReportId, b=> b.Id, (fir2, report) => new { fir2, report}) .Where(q=> q.fir2.fir.ReportId==reportId) .Select(res => new FundsResponse() { FundId = res.fir2.fund.Id, LegalName = res.fir2.fund.LegalName, HeaderName = res.fir2.fund

Timeout period elasped prior to obtaining a connection from the pool - Entity Framework

老子叫甜甜 提交于 2021-02-05 08:39:31
问题 I have an ASP.NET MVC application that is deployed on Azure app service. I'm debugging this application on my local and its using IIS express. No IIS installed on the Windows 10 system. My code is written like this: The user login is getting validated like this try { using(var context = new techEntities()) { wtuser u = (from c in context.wtUsers where c.email == email select c).FristOrDefault(); if(u == null) { return new userOT {error = "Invalid email or password"}; } ... } } catch(exception

Entity Framework Core many-to-many navigation issues

社会主义新天地 提交于 2021-02-05 07:09:41
问题 Entity Framework Core has yet to implement many-to-many relationships, as tracked in GitHub issue #1368; however, when I follow the navigation examples in that issue or similar answers here at Stack Overflow, my enumeration fails to yield results. I have a many-to-many relationship between Photos and Tags. After implementing the join table, examples show I should be able to: var tags = photo.PhotoTags.Select(p => p.Tag); While that yields no results, I am able to to load via: var tags =

Entity Framework Core many-to-many navigation issues

你说的曾经没有我的故事 提交于 2021-02-05 07:09:38
问题 Entity Framework Core has yet to implement many-to-many relationships, as tracked in GitHub issue #1368; however, when I follow the navigation examples in that issue or similar answers here at Stack Overflow, my enumeration fails to yield results. I have a many-to-many relationship between Photos and Tags. After implementing the join table, examples show I should be able to: var tags = photo.PhotoTags.Select(p => p.Tag); While that yields no results, I am able to to load via: var tags =

Entity Framework Core many-to-many navigation issues

混江龙づ霸主 提交于 2021-02-05 07:09:23
问题 Entity Framework Core has yet to implement many-to-many relationships, as tracked in GitHub issue #1368; however, when I follow the navigation examples in that issue or similar answers here at Stack Overflow, my enumeration fails to yield results. I have a many-to-many relationship between Photos and Tags. After implementing the join table, examples show I should be able to: var tags = photo.PhotoTags.Select(p => p.Tag); While that yields no results, I am able to to load via: var tags =

Entity Framework Core many-to-many navigation issues

匆匆过客 提交于 2021-02-05 07:09:15
问题 Entity Framework Core has yet to implement many-to-many relationships, as tracked in GitHub issue #1368; however, when I follow the navigation examples in that issue or similar answers here at Stack Overflow, my enumeration fails to yield results. I have a many-to-many relationship between Photos and Tags. After implementing the join table, examples show I should be able to: var tags = photo.PhotoTags.Select(p => p.Tag); While that yields no results, I am able to to load via: var tags =

How can I query the foreign key objects using Entity Framework?

允我心安 提交于 2021-02-05 06:45:06
问题 I am trying to learn about Entity Framework 6, and I am running into an issue, that I have been able to reproduce in a test project: A Movie has a Name and a Revenue . A Revenue has a GrossIncome : public class Movie { [Key] public int Id { get; set; } public string Name { get; set; } public Revenue Revenue { get; set; } } public class Revenue { [Key] public int Id { get; set; } public double GrossIncome { get; set; } } I am trying to use EF6 code-first to persist some data about movies in

The entity type 'Uri' requires a primary key to be defined

痞子三分冷 提交于 2021-02-05 06:37:27
问题 I reference a common model, so I don't have control over the attributes in it. Assuming it looks like this: public class Message { public Guid Id { get; set; } public string Sender { get; set; } public Uri Uri { get; set; } } Where Uri is System.Uri . In my context I then override OnModelCreating in order to set the primary key: public DbSet<Message> Messages { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Message>() .HasKey(i => i.Id); }

Entity Framework : Filter query by property of a child type

匆匆过客 提交于 2021-02-05 05:10:21
问题 I have model as below class Person { public int Id { get; set; } public string Name { get; set; } } class Employee : Person { public string Dep { get; set; } } class Client : Person { public string Type { get; set; } } Now I would like to query Person by a property of Employee as follows context.Set<Person>().Where(x => ((Employee)x).Dep == "dep").ToList(); But I get the following error Unable to cast the type 'DomainModel.Person' to type 'DomainModel.Employee'. LINQ to Entities only supports

Many-to-many query in Entity Framework 7

假装没事ソ 提交于 2021-02-04 18:09:09
问题 I am following this example which I got from http://ef.readthedocs.org/en/latest/modeling/relationships.html class MyContext : DbContext { public DbSet<Post> Posts { get; set; } public DbSet<Tag> Tags { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<PostTag>() .HasKey(t => new { t.PostId, t.TagId }); modelBuilder.Entity<PostTag>() .HasOne(pt => pt.Post) .WithMany(p => p.PostTags) .HasForeignKey(pt => pt.PostId); modelBuilder.Entity<PostTag