entity-framework-4

Insert new object with existing object

孤人 提交于 2019-12-29 04:48:05
问题 I am new to EF 4 and this is what I have done so far: Create an edmx file based on my database Create a code generation for my objects (POCO). Now I have a model1.tt, when expanded I see al my classes Create a repository for each class, based on IRepository Now, I am working with two objects, A and B. Object A has a property of type B. In my winform I have a combo filled with objects of type B. When the save button is pressed, a new instance of class A is created and all the properties are

Entity Framework POCO SaveChanges() on Update doesn't work?

眉间皱痕 提交于 2019-12-29 04:47:28
问题 I'm working with EF CTP 4, using POCO models, adding a new object and call SaveChanges() works but updating the object doesn't work. Here's the code for update: public void UpdateContact(Contact contact) { var findContact = GetContact(contact.ContactID); findContact = contact; _context.SaveChanges(); } public Contact GetContact(int contactId) { return GetAllContacts().SingleOrDefault(c => c.ContactID == contactId); } public IQueryable<Contact> GetAllContacts() { return _context.Contacts; } I

Why do Entity Framework queries not return unsaved entities

与世无争的帅哥 提交于 2019-12-28 13:41:28
问题 Consider the following code: var Products_First = (from Entities.Product p in myContext.Product select p); Entities.Product newProduct = new Entities.Product(); newProduct.Name = "New Product"; myContext.Products.AddObject(newProduct); var Products_Again = (from Entities.Product p in myContext.Product select p); Notice here that Products_Again is queried without saving the context, that is myContext.SaveChanges() is not called. Products_Again contains the same number of products as Products

circular dependency in entity framework

心已入冬 提交于 2019-12-28 13:08:25
问题 Is it possible to save model which has got circular dependency ? I denormalized my Database: User -------- UserId UserName LastOrder - fk to last order Order ------- OrderId OrderName UserId OrderDate Is it possible to save sth like this using entityFramework? what should I change to make it work cause now I have got error: Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values. 回答1: I

Deploying database changes with EF 4.1

只谈情不闲聊 提交于 2019-12-28 12:33:10
问题 Does anyone have any best practices around deploying database changes in an EF 4.1 code-first solution? I know MS does not currently support database migrations for EF 4.1, but obviously people are going to need to do this from time to time. Thanks 回答1: Once you deployed database to production you must do incremental changes. It means that before you deploy next version you must prepare two databases in your dev box: Database with DB schema currently deployed in production - you should be

Cannot convert method group 'ToList' to non-delegate type

可紊 提交于 2019-12-28 06:36:26
问题 I'm trying to write a method that generates multiple invoices. This is for a college, where clients are enrolled with tutors in a class called Enrollments. With this method, I am trying to accumulate the monthly fee of the tutors clients multiplied by their commission percentages, as tutors earn a certain commission on the lessons they give. Here is my code for this: public ActionResult CreateBulkCommissions() { var month = DateTime.Now.ToString("MMMM"); var enrolments = db.Enrollments.ToList

Cannot convert method group 'ToList' to non-delegate type

故事扮演 提交于 2019-12-28 06:36:06
问题 I'm trying to write a method that generates multiple invoices. This is for a college, where clients are enrolled with tutors in a class called Enrollments. With this method, I am trying to accumulate the monthly fee of the tutors clients multiplied by their commission percentages, as tutors earn a certain commission on the lessons they give. Here is my code for this: public ActionResult CreateBulkCommissions() { var month = DateTime.Now.ToString("MMMM"); var enrolments = db.Enrollments.ToList

How map objects to a view with EF 4 code first?

筅森魡賤 提交于 2019-12-28 06:18:16
问题 How can you map an entity to a database view with EF 4 code first? Is there a way to do this by deriving from the EntityConfiguration classes? 回答1: Yes! I found the answer: You can certainly use Code First to map to a view, just tell Code First that it's a table and it will use the same SQL against the view that it would for a table. Obviously if your view isn't writeable then saving is going to fail if you try and update values in the entities that are based on the view, but we will just

Dump Linq-To-Sql now that Entity Framework 4.0 has been released?

我怕爱的太早我们不能终老 提交于 2019-12-28 05:58:11
问题 The relative simplicity of Linq-To-Sql as well as all the criticism leveled at version 1 of Entity Framework (especially, the vote of no confidence) convinced me to go with Linq-To-Sql "for the time being". Now that EF 4.0 is out, I wonder if it's time to start migrating over to it. Questions: What are the pros and cons of EF 4.0 relative to Linq-To-Sql? Is EF 4.0 finally ready for prime time? Is now the time to switch over? 回答1: Well, an endless debate :-) Yes, I firmly believe EF4 is

EF Mapping and metadata information could not be found for EntityType Error

大憨熊 提交于 2019-12-28 05:35:20
问题 I have encountered an exception when I use Entity Framework 4.0 RC. My Entity Framework model is encapsulated in a private assembly who's name is Procurement.EFDataProvider and my POCO classes are inside of another assembly Procurement.Core The relation between Core(Business Logic)and EFDataProvider(Data Access) is with a factory named DataProvider so when I try to create an objectset objectSet = ObjectContext.CreateObjectSet<TEntity>(); I get an error: Mapping and metadata information could