entity-framework-5

The object cannot be deleted because it was not found in the ObjectStateManager in entity framework 5

谁说胖子不能爱 提交于 2019-11-30 06:57:59
I'm trying to delete an object using EntityFramework 5 but i get this error. The object cannot be deleted because it was not found in the ObjectStateManager I am using the Remove() method as DeleteObject() is not present in EF5. Can anyone help what am I missing? This does not work for Remove localDb.Customers.Remove(new Customer() { CustomerId = id }); localDb.SaveChanges(); Another thing I tried from msdn to change the state to Deleted. But here it gives an error saying all the fields should be present. Is it necessary to get the complete record then delete? var customer = new Customer(){

Entity framework 5.0 handle optimistic concurrency exception?

守給你的承諾、 提交于 2019-11-30 06:18:49
问题 When handling several potential exceptions during a context.SaveChanges() one of the exceptions is OptimisticConcurrency . Microsoft's documentation on this at http://msdn.microsoft.com/en-us/library/bb399228.aspx discusses this for EF 4.x ... try { // Try to save changes, which may cause a conflict. int num = context.SaveChanges(); Console.WriteLine("No conflicts. " + num.ToString() + " updates saved."); } catch (OptimisticConcurrencyException) { // Resolve the concurrency conflict by

EF 4.3.1 and EF 5.0 DbSet.Local is slower than an actual Database query

谁说我不能喝 提交于 2019-11-30 06:15:01
I've got a database with a table of about 16,500 cities, and an EF Data Model (Database-First) for that database. I preload them into memory with the code: Db.Cities.Load() ...then when it's time to use them, I've tried each of the following queries: Dim cities() As String = Db.Cities.Select(Function(c) c.CityName).ToArray Dim cities() As String = Db.Cities.Local.Select(Function(c) c.CityName).ToArray The first query is fast (~10ms), but the second one takes about 2.3 seconds to run the first time (although it's faster than the first query when it's called after that). This doesn't make sense

How should I seed data to many to many relation in Entity Framework Code first 5.0

丶灬走出姿态 提交于 2019-11-30 05:08:16
I am having my first steps in EF 5.0 I have a many to many relationship. Movie can Have multiple Types and Type can have multiple Movies public class Movie { public int MovieId { get; set; } [Required] public string Name { get; set; } public virtual ICollection<Type> Types { get; set; } } public class Type { public int TypeId { get; set; } public string MovieType { get; set; } public virtual ICollection<Movie> Movies { get; set; } } When I generated the Database it creates many-to-many between Movie and type So, What should i do to seed this many to many table? I tried many solution posted

How to get list of modified objects in Entity Framework 5

亡梦爱人 提交于 2019-11-30 04:44:34
I'm binding list of entities to a data grid view like this: var orders = context.Order.ToList(); BindingList<Order> orderList = new BindingList<Order>(orders); dataGridView1.DataSource = orderList; User can edit or add new directly on datagridview. When user click Save button, in order to optimize performance, I want to retrieve list of entities that has been changed/new to perform insert/update. How can I achieve this? EDIT Define add new row to gridview: BindinList<Order> orders = (BindingList<Order>)dataGridView1.Datasource; order.Add(new Order()); EDIT 2 Solve: BindinList<Order> orders =

EntityFramework 5 use dll version 4.4.0.instead 5.0

亡梦爱人 提交于 2019-11-30 04:41:16
I have project based on .NET 4.0 but I need to use EntityFramework 5 in my solution. So I install it from the NuGet. After that I change target framework to .NET 4.5 (I'm using VS 2012) and rebuild project. But in reference folder I see that project use EntityFramework.dll version 4.4.0.0. Ho can I use newer version of EntityFramework? in web.config <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies> </compilation> Newer version (the real EF5) is dependent on .NET 4

Code first create tables

自闭症网瘾萝莉.ら 提交于 2019-11-30 04:07:25
I was following this tutorial, and I tried to add a few new columns in the userprofile table. And i tried to create a new table. public class UsersContext : DbContext { public UsersContext() : base("DefaultConnection") { } public DbSet<UserProfile> UserProfiles { get; set; } public DbSet<TestTabel> TestTabel { get; set; } } [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string Mobile { get; set; } public string FirstName { get; set; } public string

Error when serializing EF Code First 5.0 data in WebAPI Controller

有些话、适合烂在心里 提交于 2019-11-30 04:03:37
问题 I had originally asked this question: How Do I Resolve "A specified Include path is not valid"? which was answered, and my .Include() is now working, however, when the serializer tries to work it's magic, I get the following error: You must write an attribute 'type'='object' after writing the attribute with local name '__type'. Here's what I'm doing to return the data: var everything = dc.Categories .Include(c => c.Products); My class definitions are fairly straightforward: public class

How to use a dynamic connection string using a Model First approach but still use the data model in the EDMX?

隐身守侯 提交于 2019-11-30 04:01:22
I have created an EDMX using EF 5 with the Model First approach, i.e. I started with a blank designer and modeled my entities. Now I want to be able to use this model defined in the EDMX but supply runtime SQL Server connection strings without modyfing the config file. I know how to pass a connection string to the DbContext but the issue is locating the metadata for the mappings within the assembly. For example, my EDMX has this connection string in the app.config <add name="MesSystemEntities" connectionString="metadata=res://*/Data.DataContext.EntityFramework.MesSystem.csdl|res://*/Data

Best way to insert data to multiple table MVC ASP

让人想犯罪 __ 提交于 2019-11-30 03:57:18
I have 4 tables. OperationTable, ClientTable, ClientDetails, OperationRes ClientTable ClientID Name Surname Birthday VerNumber ClientDetails ClientID Email Adress Telephone OperationTable OperationID Date Time ClientID OperationRes ResID OperationID Name Type No i have page where we ask Client to fill a form to register for smth. Everything must be in one page and after Client submit the form, we must insert all data to it's table. Date and Time to OperationTable, Name and Surname to ClientTable and so on. I'm new in ASP.NET MVC. i have tried to use "Code Fisrt". I have created Model and just