entity-framework

How to add relationship between tables in two different DbContext

柔情痞子 提交于 2021-02-08 03:35:14
问题 I have two DbContext class and some Entities in them. I know this is not good idea to have more than one DbContext but i have to do a lot of works to change my code! so my question is what is the best scenario for add relationship between two Entities with different DbContext? For example an one to many relationship between User Entity with IdentityDb Context and Comment Entity with SiteDbContext : public class User : IdentityUser { public DateTime JoinDate { get; set; } public async Task

How to create new entity object, modify it in Model before SaveChanges()

巧了我就是萌 提交于 2021-02-08 03:28:11
问题 I've been dwelling with this issue for hours and couldn't figure out the problem. So I'm using ASP.NET MVC 3 with Entity Framework 4.1. I am writing the account management controller and models from scratch. My problem is that whenever the Controller receives the filled-up entity object from the View and sends it onwards to the Model, the Model won't save it if I try to modify any of the fields beforehand. Here is the relevant portion of my model, named ModelManager.cs : public class

How to create new entity object, modify it in Model before SaveChanges()

我只是一个虾纸丫 提交于 2021-02-08 03:27:08
问题 I've been dwelling with this issue for hours and couldn't figure out the problem. So I'm using ASP.NET MVC 3 with Entity Framework 4.1. I am writing the account management controller and models from scratch. My problem is that whenever the Controller receives the filled-up entity object from the View and sends it onwards to the Model, the Model won't save it if I try to modify any of the fields beforehand. Here is the relevant portion of my model, named ModelManager.cs : public class

Entity Framework always save DateTimeOffset as UTC

巧了我就是萌 提交于 2021-02-08 02:21:12
问题 Is there a way that I can instruct Entity Framework to always store DateTimeOffset as the UTC value. Technically there is no reason for this but I prefer it if all the data in my database is consistent. Currently it is storing the DateTimeOffset as received from the client which could be anything depending on the users locale. I was thinking of perhaps intercepting all the SaveChanges method, looping through the changes, looking for DateTimeOffset types and doing the conversion explicitly,

Entity Framework always save DateTimeOffset as UTC

元气小坏坏 提交于 2021-02-08 02:19:47
问题 Is there a way that I can instruct Entity Framework to always store DateTimeOffset as the UTC value. Technically there is no reason for this but I prefer it if all the data in my database is consistent. Currently it is storing the DateTimeOffset as received from the client which could be anything depending on the users locale. I was thinking of perhaps intercepting all the SaveChanges method, looping through the changes, looking for DateTimeOffset types and doing the conversion explicitly,

Does/Will Entity Framework 6 support the new Sql Azure & Azure Active Directory Authentication

坚强是说给别人听的谎言 提交于 2021-02-07 20:43:34
问题 Does EF 6 support this method for authentication and if so what is the installation process and nuget packages to make it work? https://azure.microsoft.com/en-us/documentation/articles/sql-database-aad-authentication/ 回答1: It looks like EF6 will support this without any changes, as it "only" requires .Net 4.6, the Microsoft Active Directory Authentication Library for Microsoft SQL Server and a special connection string key, either: Authentication=Active Directory Integrated; Or Authentication

MultiShardQuery on SQL Azure Elastic Scale with Entity Framework

喜你入骨 提交于 2021-02-07 20:10:24
问题 I am new in Azure and I am trying to implement multishard query using Elastic Scale and Entity Framework. Unfortunately I am not able to find any example solutions or good practises to achieve that target. Can anyone help me in this issue? I would be very grateful for some materials to study or hints. Thank you in advance. 回答1: Thanks for your question on multi-shard queries with Elastic Scale and EF. Currently, a straight-forward integration like the one you probably saw for data-dependent

MultiShardQuery on SQL Azure Elastic Scale with Entity Framework

牧云@^-^@ 提交于 2021-02-07 20:03:43
问题 I am new in Azure and I am trying to implement multishard query using Elastic Scale and Entity Framework. Unfortunately I am not able to find any example solutions or good practises to achieve that target. Can anyone help me in this issue? I would be very grateful for some materials to study or hints. Thank you in advance. 回答1: Thanks for your question on multi-shard queries with Elastic Scale and EF. Currently, a straight-forward integration like the one you probably saw for data-dependent

How to call Stored Procedure with join on multiple tables in Entity Framework Core?

喜欢而已 提交于 2021-02-07 19:16:11
问题 I have to call a stored procedure which is selecting records from multiple tables. I have tried the following code, but it's returning null for columns from other tables than the entity class. private async Task<IEnumerable<TEntity>> InvokeStoredProcedureAsync(string input = "") { var storedProcedureName = "sp_BulkSelect"; using (var db = new MyDbContext(_options)) { var result = await db.Set<TEntity>().FromSql(storedProcedureName + " @inputIds", new SqlParameter("inputIds", input))

How to call Stored Procedure with join on multiple tables in Entity Framework Core?

隐身守侯 提交于 2021-02-07 19:15:15
问题 I have to call a stored procedure which is selecting records from multiple tables. I have tried the following code, but it's returning null for columns from other tables than the entity class. private async Task<IEnumerable<TEntity>> InvokeStoredProcedureAsync(string input = "") { var storedProcedureName = "sp_BulkSelect"; using (var db = new MyDbContext(_options)) { var result = await db.Set<TEntity>().FromSql(storedProcedureName + " @inputIds", new SqlParameter("inputIds", input))