entity-framework-6

How can I use Entity Framework 6 and my repository to delete multiple records?

守給你的承諾、 提交于 2019-12-08 01:00:59
问题 I am using Entity Framework 6 and I have a repository looking like the following with the Add and Update methods removed to make it shorter: public class GenericRepository<T> : IRepository<T> where T : class { public GenericRepository(DbContext dbContext) { if (dbContext == null) throw new ArgumentNullException("An instance of DbContext is required to use this repository", "context"); DbContext = dbContext; DbSet = DbContext.Set<T>(); } protected DbContext DbContext { get; set; } protected

Entity Framework one-to-zero-or-one foreign key association

橙三吉。 提交于 2019-12-08 00:49:35
问题 I am in the process of changing the back-end of an existing application to use Entity Framework Code First. I've used the built-in tool in Visual Studio 2015 to generate POCO classes based on my existing database. This worked perfectly for the most part, except for two classes, with a one-to-zero-or-one relationship. These are my (simplified) classes: public class Login { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int TeamMemberId { get; set

how to redirect to login page if user directly entres URL in browser using ASP.NET

天涯浪子 提交于 2019-12-07 23:05:38
问题 I am working on asp.net entity framework. I want to access the pages only through login and not directly by entering the URL of the page. If user enters the URL of the page and tries to access it then he should be redirected to Login Page. How can I do that? User are supposed to login with username and password from DB. I am new to ASP.NET 回答1: The functionality you are looking for can be achieved by adding the following authentication/authorization sections to the ASP.NET Web.config file

Save detached object graph using Entity Framework code first causes Primary Key violation

孤人 提交于 2019-12-07 18:45:44
问题 I'm trying to save an object graph of POCOs I have mapped to EF6 using Code First fluent notations. Upon saving the object graph however, I stumble upon primary key violation exceptions. The object graph is quite simple: One Issue can contain multiple WorkItems with each one Author (as User ). The objects are populated externally (using a Web API) When I attempt to save an issue with two workitems which refer to the same author, I would expect the issue to be inserted, the workitems to be

Entity Framework 6 inverting column order for composite foreign keys

£可爱£侵袭症+ 提交于 2019-12-07 18:04:37
问题 I'm getting this error: (15,10) : error 3015: Problem in mapping fragments starting at lines 6, 15: Foreign key constraint 'Beta_Alpha' from table Beta (Alpha_2, Alpha_1) to table Alpha (Alpha_1, Alpha_2):: Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side. The key information is that the composite foreign key in Beta (Alpha_2, Alpha_1) has the columns inverted, with Alpha_2 first and Alpha_1

Get ignored properties in Entity Framework

你。 提交于 2019-12-07 17:04:23
问题 I work on a framework with EF. I want to get all ignored properties of an entity to build some special queries. How can I do it? public class Customer { public int Id { get; set; } public DateTime BirthDate { get; set; } public int Age { get; set; } } public class CustomerContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Customer>().Ignore(customer => customer.Age); base.OnModelCreating(modelBuilder); } public DbSet<Customer>

How do I get EF6 to generate efficient SQL containing mulitple aggregate columns?

北慕城南 提交于 2019-12-07 15:48:25
I'm trying to get the Entity Framework (v6.1.3) to generate efficient SQL for a query with multiple aggregates. Here's a simplified example. Table: CREATE TABLE [dbo].[CaseAttorney]( [CaseAttorneyID] [int] IDENTITY(1,1) NOT NULL, [CaseNumber] [varchar](30) NOT NULL, [AttorneyID] [int] NOT NULL, [DateAssigned] [datetime] NULL, [DateUnassigned] [datetime] NULL, CONSTRAINT [PK_CaseAttorney] PRIMARY KEY CLUSTERED ( [CaseAttorneyID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] C#: using (var

How do I map a column to uppercase in .NET 4.5 C# Entity Framework 6 using both Oracle and SQL Server?

て烟熏妆下的殇ゞ 提交于 2019-12-07 15:24:13
问题 I'm using C#, .NET 4.5 and Entity Framework 6 in my project. It uses both Oracle and SQL Server, depending on the installation at the client. The approach is database-first, as this database existed already by the time we decided to change the ORM from NHibernate to Entity Framework 6. The mapping looks like this: ToTable(schema + ".Motorista"); Property(x => x.Criacao).HasColumnName("criacao").IsOptional(); The table and column names are all in PascalCase in the mapping, which works fine

Entity Framework 6 - Npgsql - connection string error

淺唱寂寞╮ 提交于 2019-12-07 15:21:28
A tricky (and frustrating problem) - perhaps you folks may be clever enough to solve it: Problem I want to be able to read/write to my database using Entity Frameworks. I have got a simple app rails running on Heroku (straightforward scaffold). I want to connect to this database and manipulate records. The good news is that I can successfully connect to that database using npgsql. The bad news is that I cannot do it with Entity Frameworks. This is the error I’m receiving: System.Data.Entity.Core.ProviderIncompatibleException: An error occurred while getting provider information from the

The entity type ApplicationUser is not part of the model for the current context. Used two different databases at beginning of project

痞子三分冷 提交于 2019-12-07 14:47:35
问题 I've created an MVC 4 application using entity framework to read and write data to a database I am hosting on an Azure database. The Azure database was supposed to keep the application data AND the login data for the application. However, when I first created the application, I had forgotten to remove the connection string to my local machine. Therefore, I had created an application that used two different databases in two different locations. One database was for the application data (Azure)