entity-framework-4.1

Entity Framework generation missing an entity

扶醉桌前 提交于 2019-12-21 07:57:19
问题 I'm trying to generate my entities from my SQL database using the ADO.NET Entity Data Model item and from there using the ADO.NET DbContext Generator. When I generate my edmx from the database one of my entities seems to be missing in the designer but when I look at the code behind of the edmx I see it in code and when I generate the dbContext the entity isn't generated at all... Any advice would be greatly appreciated! 回答1: If the table you are missing an entity for is a join table for a

Moq testing LINQ Where queries

送分小仙女□ 提交于 2019-12-21 07:06:36
问题 I'm using EF 4.1 to build a domain model. I have a Task class with a Validate(string userCode) method and in it I want to ensure the user code maps to a valid user in the database, so: public static bool Validate(string userCode) { IDbSet<User> users = db.Set<User>(); var results = from u in users where u.UserCode.Equals(userCode) select u; return results.FirstOrDefault() != null; } I can use Moq to mock IDbSet no problem. But ran into trouble with the Where call: User user = new User {

What changes are needed to move an Entity Framework 4.1 Code First application to production?

∥☆過路亽.° 提交于 2019-12-21 05:39:10
问题 As discussed in this thread, Entity Framework Code First is suited for a development environment. So, what steps or changes need to be made to an Entity Framework Code First application to move it over to Production? Migrate database to production server. Change the connection string in Web.config Any changes needed to the DbContext initialization to keep it from monkeying around in a production environment? (Or will it stay out of trouble since the database schema is correct from the

Reflection + Linq + DbSet

╄→尐↘猪︶ㄣ 提交于 2019-12-21 05:27:08
问题 I use EF code-first 4.1. in my application. Now I want to get entities through WCF services using generic types. I'm trying to reflect generic type and invoke the method ToList of DbSet Object. Here is my code: public string GetAllEntries(string objectType) { try { var mdc = Globals.DbConnection.Create(@"some_db_connection", true); // Getting assembly for types var asob = Assembly.GetAssembly(typeof(CrmObject)); // getting requested object type from assembly var genericType = asob.GetType

One to one relationship, different key column name, Entity Framework, Code First approach

核能气质少年 提交于 2019-12-21 05:11:17
问题 I have two tables that have already been created. Document and DocumentStyle . They have a one to one relationship through the DocumentID column. However, it is called Id in Document table, and DocumentId in DocumentStyle table. Something like this > Document DocumentStyle > |----------| |----------------| > |Id - Key |<------>|DocumentId- key | > |Name-VChar| |Color -VChar| > |Desc-VChar| |Font VChar | > |----------| |----------------| I'm getting the following error in VS The

One to one relationship, different key column name, Entity Framework, Code First approach

自作多情 提交于 2019-12-21 05:11:07
问题 I have two tables that have already been created. Document and DocumentStyle . They have a one to one relationship through the DocumentID column. However, it is called Id in Document table, and DocumentId in DocumentStyle table. Something like this > Document DocumentStyle > |----------| |----------------| > |Id - Key |<------>|DocumentId- key | > |Name-VChar| |Color -VChar| > |Desc-VChar| |Font VChar | > |----------| |----------------| I'm getting the following error in VS The

Entity Framework 4.1 Automatic date

天大地大妈咪最大 提交于 2019-12-21 05:06:25
问题 i'm quite new to Entity Framework (and asp.net mvc 3) and this is my really first experience with EF4.1 code first. My question is simple: when I generate via model a new table for database I would like to make Automatically add current datetime to a field when a new row is created. Automatically update the field every time the field is updated. Actually, the variable appears like: [DisplayName("Data Modifica")] [DataType(DataType.DateTime)] [DisplayFormat(DataFormatString = "{0:d}")] public

Keep Database Content On Model Change

主宰稳场 提交于 2019-12-21 05:04:58
问题 Using the code-first approach available in the new 4.1 RC. Is there any way to persist the current data stored in a database when the mode changes? The database is created by the entity framework, and usually the database is dropped and recreated on model changes. Obviously as soon as the model is changed it will not be possible to use the context object to connect to the database to retrieve the data, so what are the options? 回答1: Code first doesn't support database migration / evolution yet

DbEntityEntry.OriginalValues not populating complex properties

≡放荡痞女 提交于 2019-12-21 05:02:59
问题 I'm writing an audit trail from snippets of code found online. On the call to my SaveChanges function I loop through all the modified entities registered with the Context and build log entries from their changes. foreach (DbEntityEntry modifiedEntity in this.ChangeTracker.Entries().Where(p => p.State == System.Data.EntityState.Added || p.State == System.Data.EntityState.Deleted || p.State == System.Data.EntityState.Modified)) { // For each changed record, get the audit record entries and add

EF 4.1 EntityType has no key - composite

我是研究僧i 提交于 2019-12-21 04:22:25
问题 I have just upgraded to the latest EF 4.1 code-first using NuGet and now I am receiving an error regarding my mapping. I have this class public class UserApplication { [Key, Column(Order = 0)] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int UserId { get; set; } [Key, Column(Order = 1)] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int ApplicationId { get; set; } [ForeignKey("ApplicationId")] public virtual Application Application { get; set; } public DateTime