entity-framework-4.1

MVC .Net Cascade Deleting when using EF Code First Approach

时光怂恿深爱的人放手 提交于 2019-12-03 12:40:13
I'm pretty new to MVC and i'm having troubles with cascade deleting. For my model I the following 2 classes: public class Blog { [Key] public int Id { get; set; } [Required] public string Name { get; set; } [DisplayFormat()] public virtual ICollection<BlogEntry> BlogEntries { get; set; } public DateTime CreationDateTime { get; set; } public string UserName { get; set; } } public class BlogEntry { [Key] public int Id { get; set; } [Required] public string Title { get; set; } [Required] public string Summary { get; set; } [Required] public string Body { get; set; } public List<Comment> Comments

Manually editing database in code first entity framework

一曲冷凌霜 提交于 2019-12-03 12:21:45
I have been trying out EF 4.1 ( code first ) with MVC 3. I am thinking ahead to when the application will need changes. I tested a couple of scenarios. I like the idea of manually editing the database when the model (my POCOs) would changed. ASP.NET error when I change the model : "The model backing the 'CTCMContext' context has changed since the database was created. Either manually delete/update the database..." Now, it says that I can " manually update the database ", but I did and still get the same error . Am I missing something !!?! EDIT Does this have to do with the model hash generate

Stored Procedures and EF Code First

独自空忆成欢 提交于 2019-12-03 11:29:14
I would like to use a stored procedure to retrieve entities from a DB, I don't care about tracking changes. I just need all entities be resolved including related ones. Do I have to use SqlCommand? What about complex properties, will they be resolved too? Any other limitations you could tell me about? Thanks! Ladislav Mrnka General answer about using stored procedures in EF is here so stored procedure in pure EF will not handle navigation properties. The answer also mentioned EFExtensions but that is not available in DbContext API. To execute stored procedure in DbContext API use: var entities

Entity Framework 4 - Mapping non-public properties with CTP5 (code first) in a persistence unaware context

£可爱£侵袭症+ 提交于 2019-12-03 11:19:39
I know the question already has a solution (eg. this question ) but I really can't afford to attach the mapping logic in the same assembly where the domain (POCO classes) is. Is there any other way? I found this nice blog post but I couldn't get it working. Here is the model: public class Institute { /** Code omitted **/ protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; } private InstituteTextSet _TextSets; public InstituteTextSet Texts { get { if (_TextSets == null) _TextSets = new InstituteTextSet(InnerInstituteTexts); return _TextSets; } } } Mapping code: var

How can I return a datareader when using Entity Framework 4?

只谈情不闲聊 提交于 2019-12-03 10:34:29
I want to define a database query using LINQ and my EntityFramework context but I don't want entities returned; I want a datareader! How can I do this? This is for exporting rows to a CSV. Cheers, Ian. This question is around EF 4, but for anyone else with EF 6 or higher you can use the AsStreaming() extension method. http://msdn.microsoft.com/en-us/library/dn237204(v=vs.113).aspx If you need this you are more probably doing something unexpected. Simple iteration through materialized result of the query should be what you need - that is ORM way. If you don't like it use SqlCommand directly.

EF 4.1 SaveChanges not updating navigation or reference properties

主宰稳场 提交于 2019-12-03 10:11:31
I'm using code first and can add records without a problem. The database is created properly and is seeded without any problems. But calling SaveChanges() in my Edit action only updates the entity, not any of the navigation or reference properties. A simplified version of my model: public class Contact : IMyBaseObject { public Contact() { this.Delete = false; this.ContactTypes = new HashSet<ContactType>(); } public int Id {get; set;} public string Name {get;set;} public bool Delete {get;set;} public virtual ICollection<ContactType> ContactTypes { get; set; } public virtual USState USState {

EF Code First thinks database is out of date — only in production

落花浮王杯 提交于 2019-12-03 10:03:52
I have an ASP.NET MVC 3 app that is using SQL Server CE 4.0 and Entity Framework 4.1 Code First. It works fine locally , but in production, it fails with the following error: The model backing the 'foobar' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data. I've verified that my application dll and database file are up-to-date on the

EF 4.1 DbContext Generattor - Put Entities in different project?

被刻印的时光 ゝ 提交于 2019-12-03 09:55:41
问题 As a part of our application architecture, we like to define clear lines between our functional layers. A typical application solution, therefore, will contain: Entity Model Task Presenter FrontEnd These end up being completely distinct assemblies. The Entity/Model delineation is done to keep database access functionality in a separate layer from our POCOs, so that only Task ever need know about Model, while everyone up to Presenter knows about Entity This works well when using Code-First or

Deploy Entity Framework Code First Database

纵然是瞬间 提交于 2019-12-03 09:13:28
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First database. Now I would like to create a comprehensive zip file containing the database, the application package generated by Visual Studio 2010 and a script to deploy everything to a Windows 2008 server with IIS7 and SQL Server 2008 with a prepared (but empty) database. I don't foresee any problems with the deployment of the application package, but I'm unsure of what approach to use in deploying the database. The target environment already has an empty database that's been assigned to me, but I've been told that

SQL Server 2008 connection string for entity framework 4.1 code first

好久不见. 提交于 2019-12-03 09:13:15
问题 I need a valid SQL Server 2008 connection string for Entity Framework 4.1 code-first project. I would use it now with MVC 3. For now it's still very simple, only 1 project, 3 simple model class... I could only find everything else, like Sql Express, CE connections on the web... Finding it by name in web.config ("ApplicationServices") is OK, because when I tried to use I got specific errors for that. The best I could get is: Unable to load the specified metadata resource. I tried to give it