ef-code-first

Creating DbContext with both custom ConnectionString and DbProviderInfo

此生再无相见时 提交于 2019-12-23 01:47:27
问题 We have a plethora of databases all sharing the same schema. They are spread about on a number of SQL Servers, some 2005, some 2008. We are getting an exception when connecting to a 2005 server AFTER having connected to a 2008 server first stating the following: An error occurred while updating the entries. See the inner exception for details. An error occurred while updating the entries. See the inner exception for details. The version of SQL Server in use does not support datatype

Publish ASP.NET MVC 5 website to Windows Azure

蓝咒 提交于 2019-12-23 01:13:58
问题 I have recently changed by asp.net MVC app to use MVC 5. It also uses entity framework 6. I have published to Azure Website numerous times in the past, but never with two code first migration configurations. I think this is my problem but I don't know how to fix it. I have two DbContext classes. One for my domain models and the other for the Identity models. On my local development machine this has caused me no issues. I also have a seed method in the Identity configuration class to create a

Hold Old and New value in SaveChange as DbEntityEntry.Entity to Audit

為{幸葍}努か 提交于 2019-12-23 00:41:09
问题 As you know we can Audit object in SaveChange() but I have some problem with Modified and Deleted entities as following, First I am using Audit.Net(this is very simple to use) to Audit my objects the below method should do audit as: private int SaveAuditRecord(DbEntityEntry dbEntry, string userGUID) { Logging.Log(LoggingMode.Error, "Saving Audid Entry{0}....", dbEntry.ToString()); DateTime changeTime = DateTime.UtcNow; TableAttribute tableAttr = dbEntry.Entity.GetType().GetCustomAttributes

Reusing a GUID in EF Code First DatabaseIntializer

谁说胖子不能爱 提交于 2019-12-23 00:22:08
问题 So I am trying to build Custom membership using EF. I dont really know what i am doing but it has gone fairly smooth so far. I am on the Database Initializer step where i am trying to dump data into the database soon as the project runs. My class Application.cs uses a GUID as a primary key as seen below. I am trying to figure out how i can add that GUID into the database. I don't know if this is possible but this is what i am trying to do. I took the default login's Database you get when you

Entity Framework Code First Tree Model

為{幸葍}努か 提交于 2019-12-22 20:00:36
问题 I have the following entity: public class Module { public Module() { SubModules = new List<Module>(); } public int Id { get; set; } public string Title { get; set; } public string Action { get; set; } public string Controller { get; set; } public string Icon { get; set; } public List<Module> SubModules { get; set; } } Which, when initialised through Code First generates the following table Schema: CREATE TABLE [dbo].[Modules]( [Id] [int] IDENTITY(1,1) NOT NULL, [Title] [nvarchar](max) NULL,

.Net Core 3 and EF Core 3 Include Problem (JsonException)

 ̄綄美尐妖づ 提交于 2019-12-22 19:23:49
问题 I'm trying to develop an application using .NET Core 3 and EF Core. I encountered an error that I could not find a solution for. I could not do on ".Net Core 3" a structure which can be simply created with PHP eloquent. Model; public NDEntityContext(DbContextOptions<NDEntityContext> options) : base(options) { } public DbSet<User> Users { get; set; } public DbSet<Order> Orders { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<User>(entity =>

EF Code first 4.3 naming convention foreign key

谁说胖子不能爱 提交于 2019-12-22 18:26:15
问题 I have the following entity: public class User { public int ID {get; set;} public int GroupID {get; set;} // navigation property with public Group Group {get; set;} // foreign key field public Adress Adress {get; set;} // navigation property only } The table generated from entity framework looks like: ID GroupID Adress_ID I don't like, that the column naming for the FK columns is not the same. Can I achieve that both use the same convention either "GroupID, AdressID" or "Group_ID, Adress_ID"?

Incorrect usage of spatial/fulltext/hash index and explicit index order EF

风流意气都作罢 提交于 2019-12-22 18:12:15
问题 I am getting Incorrect usage of spatial/fulltext/hash index and explicit index order this error while trying to login. I am not using Entity Framework migration. [DbConfigurationType(typeof(MySqlEFConfiguration))] public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("DefaultConnection") { } static ApplicationDbContext() { // Set the database intializer which is run once during application start // This seeds the database with admin user

EF 5RC Table splitting into more than two entities

余生颓废 提交于 2019-12-22 12:54:15
问题 Can someone provide an example or explain how can I split a table into more than two entities using data annotations on EF 5 RC Code First? I have 4 entities I want to be mapped into just one table. The code for each one of them are: [Table("PatientDataEntities")] public class PatientDataEntity { [Key] [ForeignKey("UserFullName")] public virtual Guid Id { get; set; } public virtual UserFullNameEntity UserFullName { get; set; } public virtual GeneralData GenData {get; set;} [ForeignKey("Id")]

EF Code First migrations: Table Per Hierarchy Bug

你说的曾经没有我的故事 提交于 2019-12-22 09:56:02
问题 Often we might need to use Entity Framework Code First with an existing database. The existing database may have a structure the allows "Table Per Hierarchy" inheritance. Or we might start with an object model that looks like: public partial class Person { public int Id { get; set; } public string Discriminator { get; set; } public string Name { get; set; } public Nullable<int> StudentTypeId { get; set; } public virtual StudentType StudentType { get; set; } } public partial class StudentType