entity-framework-4.1

Ordering Column Attributes in Entity Framework

旧街凉风 提交于 2019-12-14 03:45:20
问题 I am using Entity Framework in my application,so I have mapped my property objects to database objects. The property objects have been defined using Column attribute. Now,I want to order them,but I can't find the property in Column Attribute for Order. I have included System.ComponentModel.DataAnnotations,but still not getting it Thanks in advance 回答1: just use : using System.ComponentModel.DataAnnotations.Schema; Code : [Column("Name" , Order = 1)] public int UserName { get; set; } Notice :

different way to connect with entity framework

こ雲淡風輕ζ 提交于 2019-12-13 22:23:18
问题 It's there another way about how can I made the database connection with entity framework instead the use of connection string in the web.config. Maybe passing the parameters to the modelBuilder or to the DBContext???? 回答1: I do believe that you can pass connection string in the parameter to the DataContext. What have you tried? Why do this? check out this link 回答2: this may be useful: in the source of MyEntities: public partial class MyEntities : ObjectContext { #region Constructors ///

EF 4.1 Code First - Mapping a one to one relationship with non standard column names

梦想的初衷 提交于 2019-12-13 19:15:46
问题 I know a lot of people is asking about one-to-one relationships on EF 4.1 but I can't seem to find an answer for this problem. I have these POCO classes: public class Contact { public decimal nCont_id { get; set; } public virtual WebsiteMembership WebsiteMembership { get; set; } //a bunch of other properties } public class WebsiteMembership { public int WebsiteMembershipId { get; set; } public virtual Contact Contact { get; set; } } Website membership's primary key (WebsiteMembershipId) is

Entity Framework projection into class is faster than selecting EF POCO objects, WHY?

半城伤御伤魂 提交于 2019-12-13 16:54:14
问题 This one confounds me. I am using EF 4.1 and have applied a T4 template to the model to use POCO's and POCO proxies (public paramaterless ctor, all properties are virtual, all navigation properties are ICollection). I have a table with around 1.1M records in it. I was doing some timing tests to see how long it takes to retrieve this data and got some unexpected results. This call returns in about 21 seconds: ctx.Valuations.MergeOption = MergeOption.NoTracking var entityValuations = ctx

How to query a complex result set from EntityFramework and display the result set in MVC.

梦想与她 提交于 2019-12-13 16:23:51
问题 I am working in MVC3, C# and using Razor. I don't work with MVC on a consistent basis so I am constantly having to relearn things... I want a view that displays a list of schools (from a specified state) with a nested list of the students (from that school) that have the middle name 'Bob'. Seems simple enough but so far I am not able to find a solution. Ex: VIEW Results for Maryland My First School: - Billy Bob Johnson - Sally Bob Simpson - Adam Bob Jones Another School: - Arnold Bob Smith -

Changing Entity's State in Entity Framework 4.1

核能气质少年 提交于 2019-12-13 16:04:25
问题 Let say we have a Customer object which has an Order object. The Order object has OrderDetail object. Customer oCustomer using(var context = new MyContext) { oCustomer = context.Include("Order.OrderDetail").Find(1); } oCustomer.Name ="blah blah"; oCustomer.Order.Description = "blah blah"; oCustomer.Order.OrderDetail.Quantity = 10; Now when I change the state of Customer as following: using(var context = new MyContext) { context.Entry(oCustomer).State = EntityState.Modified. context

How can I map an Enum using Entity Framework 4.1 Fluent API?

喜你入骨 提交于 2019-12-13 15:23:45
问题 I've gotten somewhat lost between the sheets of EF... Like the rest of the free world, I really have a need to use Enums in my POCOs. Like many I talk to, I would thoroughly enjoy mapping Enums using code only because, well I just don't like pictures all that much. My quandary here is that I am getting conflicting information on nearly every article I pull up. It gets even harder sifting out the custom implementations or "extensions" people have published to try and work around the EF

Entity Framework 4.1 Code-First approach to realize many-to-many relation over Domain-Services

♀尐吖头ヾ 提交于 2019-12-13 15:14:10
问题 I had some problems while creating a database model using the newest Entity Framework and Code-First (see Entity Framework 4.1 Code First approach to create many-to-many relation for details). Meanwhile I've figured out that the problem isn't the Entity Framework itself any more, but using it along with WCF RIA DomainServices. For the sake of completeness - that's my relevant Code-First code: // // Models // public class Author { public Author() { this.Books = new Collection<Book>(); }

Mutilevel include in C# Linq

妖精的绣舞 提交于 2019-12-13 13:20:54
问题 I want to have MULTILEVEL include in my linq statment, something like var a = departments.include(u=>u.Customers) .include(u=>u.Customers.Include(u=>u.Orders); How should i do that? Thanks 回答1: You of course can use lambda expression but you must use special format: var a = departments.Include(d => d.Customers.Select(c => c.Orders)); 回答2: This should do the trick: departments.Include("Customers.Orders"); Obviously you can't use a lambda expression anymore. cf. documentation here: http://msdn

Problem with SaveChanges() Entity Framework 4.1

半世苍凉 提交于 2019-12-13 12:40:07
问题 I am having problem with saving the changes to database. I am updating the model A in my controller, however when I save the changes using SaveChanges() I end up having a duplicated item in database for B. After the UpdateModel() is called I inspected the Bs property and it was as I expected however right after the SaveChanges() is called if I inspect the Bs property I will see that the Id is completely different (new Id and new entry). My class is similar to this: public class A {