code-first

EF Code First CREATE DATABASE permission denied in database 'master'

天大地大妈咪最大 提交于 2019-12-11 03:23:55
问题 I used code first for create and update database. My update-database commands in package manager worked until yesterday. But today it is not working and has this error: CREATE DATABASE permission denied in database 'master'. I do not any changes on connection string and other config. So I try to Update-database to another project on my system and my windows and I can recreate and update this database without any problem. Can you help me for fix this error? This is my connection string for

How do I add a column to a table (schema upgrade) and have it map to an EF code first object

大兔子大兔子 提交于 2019-12-11 02:54:28
问题 I have a database that I created for a site using Entity Framework 4.1 code first. I need to add a simple property to one of my entity classes, and add a corresponding (possibly nullable) column to the database without losing any of the data in the database. I think I can take down the site, alter the database to add the column, and redeploy website with an updated entity class, but I'm not sure that's the best way to do this schema upgrade. Is there a standard (or just better) way of doing a

How to generate and auto increment Id with EF Core Oracle

こ雲淡風輕ζ 提交于 2019-12-11 02:54:11
问题 I use entity framework core 2 Code first to generate data in Oracle 11g, the entity provider is dotConnect, my POCO class is as follow: public partial class Favoritepage { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int Personnelid { get; set; } public int Pageid { get; set; } } My DbContext is as follow: public partial class ModelContext : DbContext { public virtual DbSet<Favoritepage> Favoritepage { get; set; } protected override void

How create composite foreign key to table with composite primary key

对着背影说爱祢 提交于 2019-12-11 01:48:30
问题 I have two tables with composite primary keys: public class Event { [Key] [Column(Order = 1)] public string ID1 { get; set; } [Key] [Column(Order = 2)] public int ID2 { get; set; } public DateTime EventDate { get; set; } public string DocID1 { get; set; } public int DocID2 { get; set; } } public class EventDocument { [Key] [Column(Order = 1)] public string ID1 { get; set; } [Key] [Column(Order = 2)] public int ID2 { get; set; } public string Name { get; set; } public string SurName { get; set

Entity Framework include Extension Returns a Ton of Data

核能气质少年 提交于 2019-12-11 01:08:23
问题 I have two entities, User and UserPermission. The User entity contains all your normal fields, Id, Username, Email, etc and the UserPermission entity has two values, UserId and PermissionId. I have written a repository method GetUserWithPermissions that originally utilized the Include extension and did something like this: return dbContext.Users.Include(u => u.UserPermission).Where(u => u.Username.Equals(username)).FirstOrDefault(); It works great but the issues is that there are going to be

entity framework code first and view mapping

[亡魂溺海] 提交于 2019-12-10 21:55:33
问题 I have a application using code first; in search section I have to gather information from 3 tables and their related tables so I made a view; and since there is no syntax for code first to create view (I think so; please let me know if I'm wrong) I used pure SQL script; on model creating to prevent EF to create a table with same name as table (VIEW_SEARCH) I did : protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Ignore<View_Search>(); } any ways application

Entity Framework CTP 5 - Code First Mappings - Can't map properly an enum list

风格不统一 提交于 2019-12-10 20:08:56
问题 I have the following [DataContractAttribute] public class Animal { [Key] [XmlElement(ElementName = "Id")] [DataMember()] public Guid Id { get; set; } [XmlElement(ElementName = "AnimalType")] [DataMember()] public List<AnimalType> AnimalType { get; set; } } And i map it through the code first approach with EF to tables modelBuilder.Entity<Animal>().ToTable("Animal"); As you see I have not performed some complex mapping, but the List of AnimalType enumerations did not get mapped automatically

Code First CTP4: Table with no primary key?

守給你的承諾、 提交于 2019-12-10 18:36:03
问题 With Entity Framework and Code First, is it possible to let it create and use a table with no primary keys? I can't get this setup to work: public class Report { public virtual int ReportId public virtual ICollection<ReportChanges> ReportChanges } public class ReportChanges { public virtual Report Report public virtual string EditorName public virtual DateTime Changed } Note that I've excluded assigning a primary key in ReportChanges. But with this setup I get: " Unable to infer a key for

Is there an attribute like [Table()] to create a class that maps to a view in EF Code First?

倖福魔咒の 提交于 2019-12-10 17:52:37
问题 I am working with Entity Framework Code First, and am trying to create a class that will map to a View. I know how to do it for a table, like below: [Table("FIL002")] public class FIL002 { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)] public Int64 Payer_Number { get; set; } public string Payer_Name { get; set; } } However, I could not find an attribute for View (Like [Table(...)] . Is there one? 回答1: Views are queried in the exact same way as tables. Therefore, just use

Entity framework code first - map class with List<> of another class to multiple tables?

青春壹個敷衍的年華 提交于 2019-12-10 17:37:42
问题 I'm evaluating EF4 and have a pretty basic question...I think, that I can't seem to find an answer for.. take the following example: public class Question { public string question {get;set;} public string answer {get; set;} } public class Person { public string Id {get; set;} public string Name {get; set;} public List<Question> Questions {get; set;} } Then I have the following tables in the database Person ( id, name ) Question ( id, personId, question, answer, ) Can I use the EF4 code first