entity-framework-core

Entity Framework map model class to table at run time

血红的双手。 提交于 2021-02-05 10:30:26
问题 In a project using ASP.NET Core 2.0 and Entity Framework, I'm trying to map a known table schema (coded into class MyTableClass ) to an unknown table name. This table name is given by the user at run time, so this is done outside of the OnModelCreating method of the Context class. Is there a way to do something like the following pseudocode: void OnUserEnteredTableNameFromUI(string tableName) { var modelBuilder = new ModelBuilder(???); // how? modelBuilder.Entity<MyTableClass>().ToTable

Entity Framework map model class to table at run time

安稳与你 提交于 2021-02-05 10:27:39
问题 In a project using ASP.NET Core 2.0 and Entity Framework, I'm trying to map a known table schema (coded into class MyTableClass ) to an unknown table name. This table name is given by the user at run time, so this is done outside of the OnModelCreating method of the Context class. Is there a way to do something like the following pseudocode: void OnUserEnteredTableNameFromUI(string tableName) { var modelBuilder = new ModelBuilder(???); // how? modelBuilder.Entity<MyTableClass>().ToTable

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

Only 1 of Multiple FK relationships Constraint

有些话、适合烂在心里 提交于 2021-02-05 08:49:06
问题 I have a logical table structure where Table A has relationship to multiple other tables ( Table B & Table C ). But functionally Table A can only ever have the FK for B or C` populated. Valid Table A Record: |------|--------|---------|---------| | ID | Name | FK_B | FK_C | |------|--------|---------|---------| | 1 | Record | -null- | 3 | |------|--------|---------|---------| Invalid Table A Record: |------|--------|---------|---------| | ID | Name | FK_B | FK_C | |------|--------|---------|--

Disable EF Core Migration verification query

无人久伴 提交于 2021-02-05 08:18:13
问题 I'm running an asp.net core 2.1.4 web application with entity framework core 2.1.4 using code first. The migration and seed are done on application startup. I've noticed a couple of EF queries checking for checking the migration history on every call: Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[_

Disable EF Core Migration verification query

倾然丶 夕夏残阳落幕 提交于 2021-02-05 08:18:06
问题 I'm running an asp.net core 2.1.4 web application with entity framework core 2.1.4 using code first. The migration and seed are done on application startup. I've noticed a couple of EF queries checking for checking the migration history on every call: Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[__EFMigrationsHistory]'); Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT OBJECT_ID(N'[_

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 =