entity-framework-5

ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

女生的网名这么多〃 提交于 2019-12-02 17:41:18
I can use package manager to run 'update-database -verbose' locally. Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server? Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable? Thanks amhed You have a couple of options: You could use update-database -script to generate the SQL commands to update the database on the server You could use the migrate.exe executable file that resides in the package folder on /packages/EntityFramework5.0.0

Filter all navigation properties before they are loaded (lazy or eager) into memory

耗尽温柔 提交于 2019-12-02 16:23:44
For future visitors: for EF6 you are probably better off using filters, for example via this project: https://github.com/jbogard/EntityFramework.Filters In the application we're building we apply the "soft delete" pattern where every class has a 'Deleted' bool. In practice, every class simply inherits from this base class: public abstract class Entity { public virtual int Id { get; set; } public virtual bool Deleted { get; set; } } To give a brief example, suppose I have the classes GymMember and Workout : public class GymMember: Entity { public string Name { get; set; } public virtual

How to initialize database with Entity Framework and Membership tables

倾然丶 夕夏残阳落幕 提交于 2019-12-02 15:15:32
I have a MVC4 web application that use Entity Framework 5.0 Code First. In Global.asax.cs I have a bootstrapper that initialize the Entity.Database, force the database to be initialized and initialize the database for the Membership. The code is this one: System.Data.Entity.Database.SetInitializer(new DatabaseContextInitializer()); Database.Initialize(true); WebSecurity.InitializeDatabaseConnection(DEFAULTCONNECTION, "UserProfile", "UserId", "UserName", autoCreateTables: true); The DatabaseContextInitializer is very simple for the moment: public class DatabaseContextInitializer :

How to rename a database column in Entity Framework 5 Code First migrations without losing data?

做~自己de王妃 提交于 2019-12-02 15:02:29
I got the default ASP.NET MVC 4 template successfully running with EF 5.0 Code First Migrations. However, when I update a model property name, the corresponding table column data is dropped by EF 5.0. Is it somehow possible to rename the table column without dropping data in an automated way? Manually edit the Up and Down methods of the migration to use the RenameColumn method to replace the AddColumn and DropColumn that it automatically generates for you. Zanon As already said , replace the AddColumn and DropColumn that is automatically generated with RenameColumn . Example: namespace

EF5 one-to-one without navigation

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:53:11
问题 I'm trying to do a one-to-one relationship, with the navigation property just on one side (MVC4, EF5, code first). public class User { public int UserId { get; set; } //PK public int RankId { get; set; } //FK public virtual Rank { get; set; } //Navigation } public class Rank { public int RankId { get; set; } } Configuration: public class RankConfiguration : EntityTypeConfiguration<Rank> { public RankConfiguration() { HasKey(e => e.RankId); Property(e => e.RankId) .HasDatabaseGeneratedOption

EF5 one-to-one without navigation

你。 提交于 2019-12-02 12:04:47
I'm trying to do a one-to-one relationship, with the navigation property just on one side (MVC4, EF5, code first). public class User { public int UserId { get; set; } //PK public int RankId { get; set; } //FK public virtual Rank { get; set; } //Navigation } public class Rank { public int RankId { get; set; } } Configuration: public class RankConfiguration : EntityTypeConfiguration<Rank> { public RankConfiguration() { HasKey(e => e.RankId); Property(e => e.RankId) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); } } public class UserConfiguration : EntityTypeConfiguration<User> {

Why are there missing client-side results when using OData options with Entity Framework DBContext?

拜拜、爱过 提交于 2019-12-02 11:29:05
OData and Entity Framework are suppose to work well together, in that OData options will be passed to the EF db context to filter queries - ie. return only the number of records requested from the server as not to inflate the payload rather than all the records then filter. Given the following URL path: /api/Users?$top=10&$skip=10 Given the following controller action: [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)] public IEnumerable<USER> Get(ODataQueryOptions<USER> options) { var dbContext = new ATMS.DAL.AtmsContext(); //var ret = options.ApplyTo(dbContext.USERS).Cast<USER>()

A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name ''

試著忘記壹切 提交于 2019-12-02 10:01:59
I wonder if you could help. I get the above error when I call .Include() . It breaks when I include tblMemberships . this.dbContext.Configuration.LazyLoadingEnabled = false; List<tblCustomerInfo> customers = this.dbContext.tblCustomerInfoes.Include("tblUsers").Include("tblMemberships").ToList(); The reason is because the navigation property between tblCustomerInfo and tblMemberships does not exist. tblUsers is the link between the other two tables. Customer -- 1:* -- User -- 1:* -- Membership (Sorry, can't include image as my reputataion < 10). My questions are: What do I need to do in order

Can I implement Entity Framework 5 TPT on Windows XP?

点点圈 提交于 2019-12-02 07:19:39
Examples of EF5 Table Per Type that I have found, such as this one use the [Table("tablename")] attribute to mark a class as defining a table. When I add this attribute I get errors: Error 1 The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses\Classes.cs 599 6 DomainClasses Error 2 The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?) E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DomainClasses

Map tables relationship from legacy database w/ entity framework with only primary keys

僤鯓⒐⒋嵵緔 提交于 2019-12-02 06:39:36
data (table name) dataid PK, value1, value2, value3 data_address (table name) dataaddressid PK, dataid - id to errenddataid, addressid1 - id to en addressid, addressid2 - id to en addressid, type address (table namne) addressid PK - id to addressid1 or addressid2, address1, address2, name, zipcode, city I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that! If you are certain that the database's integrity is sound you could just map the tables and create the associations manually in the EF model. In