- http://kb.cnblogs.com/page/100038/
- 官方的学习资料:http://msdn.microsoft.com/en-us/data/ee712907
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application
- http://blogs.msdn.com/b/rickandy/archive/2013/02/12/seeding-and-debugging-entity-framework-ef-dbs.aspx
- http://stackoverflow.com/questions/25733790/ef-6-1-error-trying-to-establish-recursive-relationship-self-referencing-table
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/connection-resiliency-and-command-interception-with-the-entity-framework-in-an-asp-net-mvc-application
- http://forums.asp.net/t/1945541.aspx?Update+navigation+property+in+Entity+Framework
- https://msdn.microsoft.com/en-us/data/jj591617.aspx#PropertyIndex
- http://blog.staticvoid.co.nz/2012/7/17/entity_framework-navigation_property_basics_with_code_first
- https://msdn.microsoft.com/zh-cn/library/system.data.entity.modelconfiguration.conventions(v=vs.113).aspx
- creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
- code first: http://www.asp.net/mvc/overview/getting-started/introduction/adding-a-model
- database first: http://www.asp.net/visual-studio/overview/2013/aspnet-scaffolding-overview
- Data Annotation: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx
- Bundling and minification
- How to create additional index in database manually?
在StackOverflow上的问题及答案:http://stackoverflow.com/questions/5040795/adding-index-to-a-table/5041221
示例代码如下:
var query = from p in context.Persons where p.Name.Contains("abc") select p;
...
public class MyInitializer : CreateDatabaseIfNotExists<MyContext> { protected override void Seed(MyContext context) { context.Database.SqlCommand("CREATE INDEX IX_Person_Name ON Person (Name)"); } }
- Some commands while using Entity Framework 4.3.
- Clear
- Enable-Migrations [-ContextTypeName Mvc4App.Models.UsersContext]
- Add-Migrations InitialCreate
- Update-Database –?
- Add-Migration AddProductPrice
- here “AddProductPrice” is arbitrary for the migration
- Update-Database [-Verbose]
- apply the changes
- Update-Database -TargetMigration : “InitialCreate” [-Force]
- Update-Database –Script
- Update-Database –Script –SourceMigrations|$InitialDatabase –TargetMigration|”AddProductPrice”
- or rollback to an empty database: Update-Database –TargetMigration:$InitialDatabase
Reference:
- http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
- http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
- http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-a-new-field
- Take care with EF4.3 AddOrUpdate method
- getting-started-with-ef-using-mvc
- Code First Mirgrations in Entity Framework
- Running & Scripting migrtions From Code
- Reading Related Data with the Entity Framework in an ASP.NET MVC Application
- creating-an-entity-framework-data-model-for-an-asp-net-mvc-application -- VERY GOOD TUTORIAL
- 在MySql中使用EntityFramework
http://msdn.microsoft.com/en-us/data/jj730568
http://forums.mysql.com/read.php?174,601264,601264 - 在调用Update-Database 时出错,提示:Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. 同时发现网站加入 migrator.Update()也报异常,提示查看EntityValidationErrror。
解决方法:在数据升级代码加上try{}catch(DbEntityValidationException ex){} 进一步debug一下查看DbEntityValidationException详情。
try { var migrator = new DbMigrator(new Configuration()); migrator.Update(); } catch (DbEntityValidationException ex1) { //CHEKC ex1.EntityValidationErrors here } catch (Exception ex2) { Debug.WriteLine(ex2.Message); }
- The name ‘ViewBag’ does not exist in the current context.
Answer: You need to add the MVC-specific Razor configuration to your web.config
- Hot to imports namespace in Razor view?
For C#: @using MyNamespace
For VB.NET: @Imports MyNamespace
另一种做法是找views文件夹下面的web.config 文件,修改namespaces节点。
<system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> . . <!-- etc --> </namespaces> </pages> </system.web.webPages.razor>
reference: http://stackoverflow.com/questions/3239006/how-to-import-a-namespace-in-razor-view-page
Questions And Answers for MVC
- How to use AreaRegistration
选中Web项目,右击 "add”, 选择Area,在弹出的窗口中输入想添加的Area名称。
- How to specify a different master layout
- How to specify the data column’s type in database, like NText?
- How to create custom HTML helper?
- How to display a navigation property witch is type of ICollection<T> type?
- Introducing System.Web.Providers – ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQ Compact and SQL Azure
- 对于在实体类中枚举类型的属性如何处理,目前EF不会为枚举类型的字段创建相应的表字段。
private int _columnTypeInt = (int)SiteColumnType.CommonContent; [Required] public int ColumnTypeInt { get { return _columnTypeInt; } set { _columnTypeInt = value; } } public SiteColumnType ColumnType { get { return (SiteColumnType)ColumnTypeInt; } set { ColumnTypeInt = (int)value; } }
- 如何进行实体拆分:
Reference:
http://msdn.microsoft.com/zh-cn/magazine/hh126815.aspx
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Post>() .Map(m => { m.Properties(p => new { p.Title, p.Content }); m.ToTable("Posts"); }) .Map(m => { m.Properties(p => new { p.Photo }); m.ToTable("PostPhotos"); }); }
- SelectList:
http://www.itstrike.cn/Question/b7cb01cb-67f5-4379-84d3-c9cfaaad2304
Trouble fixings:
- Using LocalDB with Full IIS, Part 1: User Profile http://blogs.msdn.com/b/sqlexpress/archive/2012/06/12/10245900.aspx
- EF有内置缓存,如何进行缓存清理?
- 局部修改 http://stackoverflow.com/questions/12661881/exclude-property-on-update-in-entity-framework