entity-framework-4.1

asp.net mvc page is not showing properties from associated objects

做~自己de王妃 提交于 2019-12-02 14:38:16
问题 I have the following simple structure: Applicant Possition ApplicantPosition and ApplicantPositionHistory The 3rd class has one reference with Applicant and one with Position. The 4th table has one reference with ApplicantPosition In the razon page I am doing to show the history of an applicant per position, I want to show the name of the applicant for example I have this in the html, however its showing me empty, it only shows me info for fields that are in the same object, for example

Code First Mapping for Entity Framework Hierarchy

吃可爱长大的小学妹 提交于 2019-12-02 13:44:43
I have a model that looks like this: public class Category { public string Id { get; set; } public string Description { get; set; } public Category Parent { get; set; } public ICollection<Category> Children { get; set; } public ICollection<Product> Products { get; set; } } With a database table that looks like Categories Id (PK varchar(5)) Description (nvarchar(50)) ParentId (FK varchar(5)) But Im stumped when it comes to setting up the mapping modelBuilder.Entity<Category>() .HasMany(x => x.Children) .WithMany(x => x.Children) .Map(m => { m.ToTable("Categories"); m.MapLeftKey(x => x.Id, "Id")

Entity Framework 4.1 RC (Code First) - Entity not updating over association

五迷三道 提交于 2019-12-02 13:35:06
问题 What I'm trying to do is fairly simple. I have two classes: public class TownRecord { public int Id { get; set; } public string ShortName { get; set; } public string FileName { get; set; } public string tags { get; set; } public virtual TownRecordType RecordType { get; set; } public DateTime? DateScanned { get; set; } public DateTime? RecordDate { get; set; } [StringLength(4000)] public string Comments { get; set; } public string UploadedBy { get; set; } } public class TownRecordType { public

Entity Framework conditional mapping with code first?

我怕爱的太早我们不能终老 提交于 2019-12-02 11:48:51
I have an entity that I need to return only records where a given field value is greater than zero. I have seen examples of conditional mapping in the edmx and that seems like what I am in need of. However, my project is in EF 4.1 code first. Is there not a way to do this using the code first approach? I dont think there is an inbuilt method for achieving this, you can however expose a property in your DbContext in which you apply filtering, initially this will be readonly but i dont see a reason why you shouldnt be able to create your own DbSet implementation reflecting back to another DbSet

Entitity Framework 4.1 - Code First- Unit testing data access layer

大兔子大兔子 提交于 2019-12-02 08:01:31
I'm a .NET developer and I'm writing tests for my data access layer. I have tests that use fake repository - I have achieved that by using Moq and Ninject. I'm getting my head around EntityFramework 4.1 Code First model and I'd like to create a prototype for CRUD routines. It's an MVC app, so my entities won't be tracked by a context. To me it feels wrong that I'm writing tests that will make changes to the database. I will then have to clear the database each time I want to run these tests. Is this the only way to test CRUD routines? Thank you How do you expect to test data access if you don

EF4 Unknown Column In Field List

孤街浪徒 提交于 2019-12-02 07:21:48
So, I am kind of stumped. I have been using a generic repository, and it works perfect. It sits on top of Entity Framework 4.1. I have used the same line of code to get a set of data numerous times and had no issues before. However, this one table in my database seems to be throwing an exception and I cannot for the life of me figure out how to fix it. This is the table design in the MySQL database Completed ========= CompletedId OldStepId NewStepId Name Step ==== StepId Name Description This is the model.cs definition public class Completed { [Key] public int CompletedId { get; set; } public

Entity Framework Code First - Cannot insert duplicate key in object 'db'

梦想与她 提交于 2019-12-02 07:20:58
I'm using the new EF code first to one project of mine, and i'm getting a weird error, my mode is: abstract class Member { public virtual int MemberId; ... some other stuff } class User : Member { public virtual string Name; ... some more props no new key defined } class MyDbContext { public DbSet<User> Users {get;set;} } The result of the deployment to SQL Server is just ok, i've a Members Table and a Users Table (TPC). Now in my main i've the following code: static Main() { User x,y; using(MyDbContext ctx = new MyDbContext()) { x = ctx.Users.Create(); y = ctx.Users.Create(); x.Name =

What's the correct way to use ObjectResult with input parameters to StoredProcedure in Entity Framework? (Output mapped to Complex Type Property)

为君一笑 提交于 2019-12-02 07:01:57
问题 I have several listboxes which have a SelectedItem property I intend to use as input parameters to execute my stored procedure in Entity Framework. I now realize my only hope for easily returning entity objects as the result of my Stored Procedure is to map the Stored Procedure (or Function Import) to a complex type which matches the output. (Used Julie Lerman's post here to make this decision.) However, I need help using ObjectResult with EntityFramework to capture my listbox SelectedItem

Sql Server CE 4 and EF 4.1 CF Win 64 bit deployment

拥有回忆 提交于 2019-12-02 06:08:17
Hi I have a following problem. I've created a project in 32 bit operating system. There I have installed EF 4.1 and SQL CE 4 for 32 bit. I've created a test table and launched it. Everything works, i.e. there is a connection to db and CRUD operations happen. In the reference pane I've set the copy local property for binaries EntityFramework.dll , System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll to true. Then I copy pasted the project into machine with x64 OS. It gives me the following error: Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture

How to read Custom Attributes using reflection set by Fluent API in EF 4.1

江枫思渺然 提交于 2019-12-02 05:39:45
I've managed to read custom attributes when I use data annotation. like following code. Object[] test = propertyInfo.GetCustomAttributes(typeof(KeyAttribute), true); But when I changed to use Fluent API. I couldn't read that attribute anymore. Any idea? Fluent API does not set attributes. Fluent API and Attributes tell EF how to build the model. These are two different ways to achieve the same thing. That is to build the Model. Edit If you need to retrieve the metadata such as primary keys you need to access the MetadataWorkspace . This article has the details. 来源: https://stackoverflow.com