entity-framework

Change IdentityServer4 Entity Framework table names

∥☆過路亽.° 提交于 2021-02-08 18:37:27
问题 I am trying to change the default table names created by the PersistedGrantDb and ConfigurationDb for IdentityServer4 and have Entity Framework generate the correct SQL. For example; instead of the using the entity IdentityServer4.EntityFramework.Entities.ApiResource using the table ApiResources , I want the data to be mapped into a table named mytesttable According to the documentation this should be as simple as adding ToTable invocations for each entity that I want to remap in the

Change IdentityServer4 Entity Framework table names

孤人 提交于 2021-02-08 18:32:32
问题 I am trying to change the default table names created by the PersistedGrantDb and ConfigurationDb for IdentityServer4 and have Entity Framework generate the correct SQL. For example; instead of the using the entity IdentityServer4.EntityFramework.Entities.ApiResource using the table ApiResources , I want the data to be mapped into a table named mytesttable According to the documentation this should be as simple as adding ToTable invocations for each entity that I want to remap in the

Entity Framework: “The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.”

对着背影说爱祢 提交于 2021-02-08 15:31:23
问题 I have this code (VS2010 ASP.NET MVC 3 with EF 4): Project project = new Project(); project.Number = number; project.Name = name; context.AddObject(project); ProjectUser projectUser = new ProjectUser(); projectUser.User = user; projectUser.Status = 1; project.ProjectUsers.Add(projectUser); context.SaveChanges(true); It generates the following error (on the "project.ProjectUsers.Add(projectUser)" line) "The relationship between the two objects cannot be defined because they are attached to

Transaction between contexts

喜夏-厌秋 提交于 2021-02-08 13:45:26
问题 I'm developing a Console Application using Entity Framework Core (7). The application is divided into 3 different areas but the database is shared. I created 3 different DbContext and now I need to perform a transaction between all of them. So I need an atomic operation the save all the changes or nothing (rollback). I know that in entity frameowrk 6 there was a class called TransactionScope but I cant find an alterntive in EF Core. Using the following code: public static void Main(string[]

How to store DateTimeOffset in PostreSQL

☆樱花仙子☆ 提交于 2021-02-08 13:43:47
问题 I am having a problem with retrieving a DateTimeOffset from a PostgreSQL database using Entity Framework. As far as researching the problem, I found this article that helps me understand what the problem is, but I can't figure out how to fix it. I have an API that allows users to upload files (mostly images) and it extracts the date that the image was taken and stores it in the database. It works great most of the time. However, if the date is between March 11 to sometime in April (date

Creating an rdlc report with multiple tables (one-to-many relationship)

南楼画角 提交于 2021-02-08 13:10:30
问题 So, I'm new to rdlc (and reporting in general actually). I have a table that has a one-to-many relationship with another table, and I'm trying to represent them in an rdlc report as multiple tables for each item . Note: The tables are originally created using Entity Framework code-first . Here are the two tables (and the parent one) : Now, normally if I only have the [Quotation] and some [QuotationItem] s, I'd just add the info from the [Quotation] on the top of the report, and the info from

Creating an rdlc report with multiple tables (one-to-many relationship)

心不动则不痛 提交于 2021-02-08 13:04:25
问题 So, I'm new to rdlc (and reporting in general actually). I have a table that has a one-to-many relationship with another table, and I'm trying to represent them in an rdlc report as multiple tables for each item . Note: The tables are originally created using Entity Framework code-first . Here are the two tables (and the parent one) : Now, normally if I only have the [Quotation] and some [QuotationItem] s, I'd just add the info from the [Quotation] on the top of the report, and the info from

UpdateRange method of Entity Framework Core does not work

房东的猫 提交于 2021-02-08 11:54:17
问题 The UpdateRange method of Entity Framework Core is used here to update multiple records but it is not working. My code is: var dept1 = new Department() { Id = 8, Name = "New Designing" }; var dept2 = new Department() { Id = 9, Name = "New Research" }; var dept3 = new Department() { Id = 102, Name = "New HR" }; List<Department> modifiedDept = new List<Department>() { dept1, dept2, dept3 }; using (var context = new CompanyContext()) { context.UpdateRange(modifiedDept); await context

Writing an extension method for Entity Framework

别说谁变了你拦得住时间么 提交于 2021-02-08 10:13:11
问题 I would like to have an extension method called FirstOrDefaultCache() which would check dbContext.EntityName.Local.FirstOrDefault(condition) , and only if that is null, check dbContext.EntityName.FirstOrDefault(condition) . I got the following from another post, which works okay: public static TEntity FirstOrDefaultCache<TEntity>(this DbSet<TEntity> queryable, Expression<Func<TEntity, bool>> condition) where TEntity : class { return queryable .Local.FirstOrDefault(condition.Compile()) // find

Entity Framework check if column exists during OnModelCreating

只愿长相守 提交于 2021-02-08 09:20:06
问题 I am maintaining this application (A) that is writing to the table of another application (B). The problem is that A writes to many B's and that the models have changed in newer versions of B. Example: A has the entity Dog with columns: Name, Age, Sex In most cases of B, this entity matches the table. But the newest version of B Dog has the columns: Name, Age, Sex, FavoritFood (which does not allow nulls) I can not change the database scheme of B, neither from code nor the sql server. If I do