entity-framework-4

How to record/audit changes for Insert/Add C# EF4

故事扮演 提交于 2019-12-11 18:38:32
问题 Is there a non-complex way of auditing Entity Changes for insert/add? I use the code below to record Entity changes for Edit/Update var context = new DBEntities(connection()); try { BPCategory Bp = context.BPCategories.First(e => e.id == id); Bp.Category = Category; Bp.PercentShare = Percent; Bp.BPCategory1 = BPCategory; Bp.Code = Code; Bp.Status = Inactive; var objState = context.ObjectStateManager.GetObjectStateEntry(Bp); var modProps = objState.GetModifiedProperties(); foreach (var

Compiler error using EF4 as a separate project than my MVC project

假如想象 提交于 2019-12-11 18:30:03
问题 I'm trying to follow the general consensus that it's best to put one's domain objects in a separate project than their MVC project, but am getting the following compiler error: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. Source File: C:\Users\Kevin\documents\visual studio 2010\Projects\HandiGamer\HandiGamer.Domain\Entities\HGDomainModel.Designer.cs Line: 44 Line 42: /// Initializes a new

How can I add properties to an association (relationship) using the Entity Framework

谁说我不能喝 提交于 2019-12-11 18:24:08
问题 I am using Entity Framework 4. I have a many-to-many association (relationship) between two entities: Account Subscription The relationship is therefore: AccountSubscription. So an account (over time) can have many subscriptions and, obviously, a particular Subscription type can be held by many Accounts at once. I want to add properties to this relationship (e.g. StartDate, EndDate, PaymentStatus). I can't see a way in Entity to add properties to an Association table. What is the best way to

c# DbSet - Internal object association cannot be got

℡╲_俬逩灬. 提交于 2019-12-11 18:17:42
问题 I have the same problem of this topic. but on the association between entities. internal virtual ICollection<Adress> Adresses { get; set; } It works if I use like this: public virtual ICollection<Adress> Adresses { get; set; } How can I initialize Adresses ? 回答1: Entity Framework will only work with public properties. If you want to use different access modifies you should check out nHibernate. 来源: https://stackoverflow.com/questions/7646182/c-sharp-dbset-internal-object-association-cannot-be

Entity Framework 4 not respecting database constraints for numeric fields

久未见 提交于 2019-12-11 18:08:35
问题 Say, I have a table in the DB defined as follows Table: Foo PkId - int, primary, autoincrement Bar - int, allow null=false, no default Now when generating the EF model from the database the 'Bar' field is correctly defined as Nullable=false, Type=Int32. Now when I do the following var foo = new Foo(); context.AddToFoos(foo); context.SaveChanges(); The row is inserted into the database and 'Bar' has a value of 0? I would have expected an exception because Bar hasn't been set. I realise that 0

EF self tracking Silverlight WCf

北城余情 提交于 2019-12-11 16:42:39
问题 Hi I have a silverlight4 + .net 4.0 application where i am using self tracking entities. In the application i have a silverlight project which contains the entities generated by EF self tracking template. This project is being shared by the wcf service and the client so that the change tracking works. everything builds fine but when i run my service is get the exception Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken

'Master Object' needs to exist without database calls

房东的猫 提交于 2019-12-11 16:36:50
问题 We're building a game, so that may help to put the objects into context better. I have a situation where I have a structure kind of like this.. - Template - Data(ICollection<Statistics>) - Character: Template - Data (ICollection<Statistics>) To elaborate... Let us assume that every character has a property "Health". Now, the default for "Health" is 15. Now let us assume that every character starts with that. As a character over its lifetime, it might add to "Health" with new values. But they

ChangeTracker.Entries<T> not returning entries with entities of Type T

谁说胖子不能爱 提交于 2019-12-11 15:11:39
问题 using EF 4.3.1 in SaveChanges(), i'm trying to get a list of all entries for entities which implement a specific interface. My entities implement multiple interfaces, one of which is IAuditable. The following doesn't return any entries, even though entries with entities of type IAuditable do exist. var auditableEntities = ChangeTracker.Entries<IAuditable>().Where( e => e.State == EntityState.Modified | e.State == EntityState.Added); 来源: https://stackoverflow.com/questions/12970257

Why does entity framework pluralize and capitalize entity class names?

丶灬走出姿态 提交于 2019-12-11 14:22:08
问题 Why does entity framework pluralize all the class names and capitalize the first letters by default? What are the advantages of doing this ? Probably a stupid question...but just out of curiosity? 回答1: In the Capitalization Conventions section of the .NET Design Guidelines for Developing Class Libraries, it states that all class names should be in Pascal case, which it defines as: "The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.

DbContext fails to initialize Model-first database

六月ゝ 毕业季﹏ 提交于 2019-12-11 13:25:08
问题 Update : It turns out I had (hidden away in my POCO objects) a property with an abstract type. Removing this property solves the issue. I'm trying to have a model-first scenario with entity framework 4 ctp 5 generate my database (currently using a SQL Server CE4 backend, but I can reproduce on a Sql Server 2008 backend) from my model. I think I might have messed up my model definition somehow, but I can't seem to figure out how and the error message leaves me none the wiser. My DbContext