entity-framework-4

updating an entity in entity framework

夙愿已清 提交于 2019-12-10 16:08:17
问题 I have an entity ( TerminalCertification ) which has relation to other entities. I want to make user to be able to update TerminalCertification but I'm not able to update related object which is updated by user. My update code is here: public void UpdateTerminalCertification(TerminalCertification terminalCertification) { var lastCertification = db.terminalCertifications.Find(terminalCertification.TerminalCertificationID); if (lastCertification==null) throw new

Setting table level WillCascadeOnDelete not available

不打扰是莪最后的温柔 提交于 2019-12-10 15:41:45
问题 I'm pulling out my hair here. I've seen the solutions to turning off cascade on delete here, but I can't implement it. I don't know what I'm doing wrong here, but I keep getting the below error: 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration' does not contain a definition for 'WillCascadeOnDelete' and no extension method 'WillCascadeOnDelete' accepting a first argument of type 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration' could be found (are you missing a

datetime2 and ProviderManifestToken in Entity Framework

你。 提交于 2019-12-10 15:34:33
问题 I have an MVC app using Entity Framework and a SQL Server 2008 database. I used the EF wizard to generate my data model. I have a SQL Server table with a standard DateTime column. The EF model is using System.DateTime . But when I try to insert a new record into this table from my application, without specifying a value for this DateTime column, I get the error: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. I Googled a bit and found that

EF Codefirst How to create separate table for derived class?

我是研究僧i 提交于 2019-12-10 15:16:27
问题 I have objects in their own tables using EF Codefirst. Now I try to produce an "archive" for changed objects living in separate tables for each of those objects. For instance: public class Person { [Key] public virtual Guid Id { get; set; } [Required] public string Name { get; set; } } public class Person_Archive : Person { [Key] [Columnn( Order = 1 )] public override Guid Id { get; set; } [Key] [Columnn( Order = 2 )] public DateTime ChangedAt { get; set; } public string ChangedBy { get; set;

Are child entities automatically tracked when added to a parent?

痞子三分冷 提交于 2019-12-10 15:14:35
问题 I want to know whether EF CodeFirst will automatically track "child" objects in the example below. var db = MyDataContext(); var order = db.Orders.Find(orderId); order.AddOrderLine("Fancy Product"); db.Commit(); Here are my (simplified) domain entities public class OrderLine { public Guid OrderLineId { get; private set; } public Guid OrderId { get; private set; } public string Description { get; private set; } public OrderLine(Guid orderId, string description) { OrderLineId = Guid.NewGuid();

EF4: Difference between POCO , Self Tracking Entities , POCO Proxies

◇◆丶佛笑我妖孽 提交于 2019-12-10 15:12:11
问题 Can someone point me the difference between POCO , Self Tracking Entities , POCO Proxies? Actually, I am working Entity Framework 4.0 and POCO(Repository Pattern) and whenever I do some changes in the POCO and call ObjectContext.Savechanges then it reflects to the DB. My question is, How does the Context persist the change to the DB since it is not tracked? Does the Context generates the tracking info on the fly for POCO? Sample Code I am using, IEFRepository<Category> catRepository = new

Any downsides to passing around a DataContext object as a 'ref' parameter?

南楼画角 提交于 2019-12-10 14:38:00
问题 So in my EF4 project I have opened up the partial classes of both the DataContext file itself, as well as a couple of the Table/Object generated by the DataContext. However, if I open up a "Products" class as a partial, there isn't (as far as I can tell) a direct link from product back up to the DataContext class that spawned it. public partial class Product { public DataContext GetContext() { return this.DataContext; // FAILS!!! No connection from 'this' to DataContext // makes sense because

How to make Entity Framework CTP5 work with SQLite?

十年热恋 提交于 2019-12-10 14:28:34
问题 I am having a very hard time in using the SQLite db with EF CTP5. I was just trying to execute this MSDN example with SQLite. But at the line var food = db.Categories.Find("FOOD"); I am getting a runtime exception: System.Data.SQLite.SQLiteException (0x80004005): SQLite errorno such table: Categories Note: The app.config file has to be modified and is as follows: App.config <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> </startup>

Entity framework doesn't save data entries in database

早过忘川 提交于 2019-12-10 14:26:01
问题 At first I should mention that this problem only occurs in windows forms applications and the same program in web mode for example with MVC3 works perfect. Some days ago I wrote a very simple windows form program using Visual studio 2010 ultimate with a SQL Express database. I added the database by choosing Add > New item > Service-Based database and an entity data model based on this database in same way. I used Entity framework for adding some new records to tables. I had done such thing

Entity Framework Code First not lazy loading after save

倾然丶 夕夏残阳落幕 提交于 2019-12-10 14:19:07
问题 I have a lookup table and a data table in my db. I'll use gender and person for an example. So let's say the gender table looks like so: Id Code 1 Male 2 Female and the person table looks like so: Id Name GenderId 1 Bob 1 2 Jane 2 I've modelled both tables in EF code first like so: public class Gender { public int Id {get;set;} public string Code {get;set;} } public class Person { public int Id {get;set;} public string Name {get;set;} public int GenderId {get;set;} public virtual Gender {get