ef-code-first

EntityFramework SqlQuery does not work with custom mapping (DataAnnotation Column)

心不动则不痛 提交于 2019-12-25 11:36:08
问题 I'm using EF 5.0 (CodeFirst) with VS 2012 and am having trouble making a query using SqlQuery. The problem happens in the mapping between the property name of the entity and the name of the column in the database. My entity (model): [Table("Teste")] public class TesteEntity { [Column("Teste_Id")] public int Id { get; set; } [Required] public bool IsAdministrator { get; set; } [Required] public string Name { get; set; } } When I run the query, I get an error. Rotine: List<TesteEntity> list =

EntityFramework SqlQuery does not work with custom mapping (DataAnnotation Column)

痞子三分冷 提交于 2019-12-25 11:36:05
问题 I'm using EF 5.0 (CodeFirst) with VS 2012 and am having trouble making a query using SqlQuery. The problem happens in the mapping between the property name of the entity and the name of the column in the database. My entity (model): [Table("Teste")] public class TesteEntity { [Column("Teste_Id")] public int Id { get; set; } [Required] public bool IsAdministrator { get; set; } [Required] public string Name { get; set; } } When I run the query, I get an error. Rotine: List<TesteEntity> list =

Upload ASP WebProject to WebHosting with Code-First EntityFramework - CREATE DATABASE 'master'

余生长醉 提交于 2019-12-25 09:15:31
问题 So I build my asp.net web project using MVC and it's working fine in localhost using code-first approach of EntityFramework 6.0. This week I bought a new Web Hosting to upload my website. The problem is that, everytime I run the website it tries to create a database in database 'master', why is this happening? I am selecting the right database that my Web Hosting provided on my ConnectionString. There is a note: I am also using ASP Identity OWIN... maybe that's the problem? it's using another

DeleteDatabase is not supported by the provider

筅森魡賤 提交于 2019-12-25 07:24:06
问题 I'm using EF Code First with SQL Express 2012. Everything worked fine until now. I'm getting this error: DeleteDatabase is not supported by the provider. public class SqlServerContext : DbContext { public DbSet<Estimate> Estimates { get; set; } public SqlServerContext(String connectionString) :base(connectionString) { Database.SetInitializer(new SqlServerContextInitializer()); } } public class SqlServerContextInitializer : DropCreateDatabaseAlways<SqlServerContext> { } Did anyone have similar

How to determine the order of Property Loading in CodeFirst?

倾然丶 夕夏残阳落幕 提交于 2019-12-25 07:23:42
问题 I was thinking that is there any way to determine the order of property loading in CodeFirst,for example i have a class like below: public Class { public string Propert1{get;set;} public string Propert2{get;set;} public List<string> PropertList{get;set;} } And i need to make EF to load ProprtyList before property1!(Because i manipulate ProprtyList Values On Property1_Changed). 回答1: A property should be just that: a property. I.e. you get or set it and nothing else, no side effects . I know

creating 1-1 relationship between two class using code first and migration

∥☆過路亽.° 提交于 2019-12-25 07:00:13
问题 Well, it is 1st time i am trying to create 1-1 relationship between two tables using code first. I took some help online and come across the following classes mapping. Than I ran migration and found something wrong. E.g. The migration says that primary key for StudentDetails is Id from Student table whereas I am looking to have primary key StudentId. Also, the foreign key is being created in opposite way. Please can someone highlight what is wrong here or is it me who perceived it wrong. I

Multi Database for Multi Tenant with Code first EF 6 and ASP.Net MVC 4

廉价感情. 提交于 2019-12-25 06:33:03
问题 I am building a SAAS application and planned for one database per client. I am using Code First EF6 with ASP.Net MVC 4. There will be 2 context i.e. MasterContext and TenantContext. User will first hit to MasterContext to authenticate user credentials and fetch its Tenant configuration. Based on fetched Tenant configuration; TenantContext is set to Tenant specific database and used for Tenant CRUD operations. Please advice how to achieve this. 回答1: The idea is to identify the current request

Code First Generic Repository with existing Database tables

怎甘沉沦 提交于 2019-12-25 05:33:29
问题 I have a Generic Repository class using code first to perform data operations. public class GenericRepository<T> where T : class { public DbContext _context = new DbContext("name=con"); private DbSet<T> _dbset; public DbSet<T> Dbset { set { _dbset = value; } get { _dbset = _context.Set<T>(); return _dbset; } } public IQueryable<T> GetAll() { return Dbset; } } I have an entity class Teacher, which maps to an existing table "Teacher" in my database, with exactly the same fields. public class

Code First Generic Repository with existing Database tables

◇◆丶佛笑我妖孽 提交于 2019-12-25 05:33:12
问题 I have a Generic Repository class using code first to perform data operations. public class GenericRepository<T> where T : class { public DbContext _context = new DbContext("name=con"); private DbSet<T> _dbset; public DbSet<T> Dbset { set { _dbset = value; } get { _dbset = _context.Set<T>(); return _dbset; } } public IQueryable<T> GetAll() { return Dbset; } } I have an entity class Teacher, which maps to an existing table "Teacher" in my database, with exactly the same fields. public class

'Update-Database' in EF 4.3 code-first - Value cannot be null

只谈情不闲聊 提交于 2019-12-25 03:52:25
问题 Using asp.NET MVC3, I am creating trying to create an abstract class/model with the following: namespace core.Models.Concrete { public class item { [Key] public Guid id { get; set; } public Type ConcreteType { get; set; } public itemtype Type { get; set; } public string barcode { get; set; } public int rating { get; set; } public string Title { get; set; } } } public enum itemtype { Game, Book, Film } Which is used by: namespace core.Models.Abstract { public class game : item { public