entity-framework-5

Data binding linq query to datagridView in Entity Framework 5.0

时间秒杀一切 提交于 2019-12-09 12:56:01
问题 I am learning the Entity Framework (5.0 and VSExpress 2012) and I'm having real trouble binding my query to a dataGridView in WinForms. I have the below code and it displays my query okay when I start the application but I don't know what I need to do to update the dataGridView after changing the data in the underlying database. What's the best way of doing this? What am I doing wrong here? private void Form1_Load(object sender, EventArgs e) { using( var ctx = new TimeKeepEntities()) { var

Entity Framework Code First Many-to-Many relationship and inheritance

此生再无相见时 提交于 2019-12-09 12:14:26
问题 Forgive me if this question has been answered somewhere, I have been having a hard time finding a solution for this problem. I am trying to set up EF Code First on an MVC4 Project. I have a User and Customer that both inherit from Person. I then have a Template object that has a Many-to-Many relationship with Customer and a One-to-Many relationship with User. Here is how I have it set up: MODELS public class Person { [Key] public int PersonID { get; set; } public string LastName { get; set; }

Is EntityFramework available for Windows 8 Store Apps?

狂风中的少年 提交于 2019-12-09 08:36:35
问题 Is EntityFramework available for Windows 8 Store Apps? I'm using Visual Studio 2012 Express for Windows 8. I'm starting to wonder because I can't make it work. I installed the Entity Framework package from NuGet I added System.Data.Entity and System.Data.Design to the project But no matter what I do, DbContext isn't recognized... Any ideas? EDIT: EntityFramework isn't available for Windows Store Apps. I don't understand Microsoft position on this, they suck. The other solution is to use

Where is the ExecuteStoreCommand method in Entity Framework 5?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 08:04:04
问题 I'm using EF5 in VS2012, and I trying to delete all data of some table using ExecuteStoreCommand , something like this: ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]"); but the problem is EF is telling me, method ExecuteStoreCommand not found. I can't understand why? Can you tell me why?, or give me a performant solution remove all data of the table. 回答1: Try this: ctx.Database.ExecuteSqlCommand 来源: https://stackoverflow.com/questions/13857242/where-is-the-executestorecommand

How to work with LocalDB and EF, without using migrations

梦想与她 提交于 2019-12-09 05:59:28
问题 I am on VS 2012 RTM, with EF 5. I am doing Code First, but trying to ignore Code Migrations since I am just in development. To avoid them, I have this set Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SomeContext>()); Occasionally, even when I don't think I've touched the model, it decides to recreate. That's fine. But it usually results in the error Cannot drop database because it is currently in use. So I decided to delete the database entirely. I go into VS, go to the "SQL

Why is DbContext.SaveChanges 10x slower in debug mode

妖精的绣舞 提交于 2019-12-09 04:41:26
问题 Can somebody explain Why does DbContext.SaveChanges run ~10x slower in debug mode than production mode? Is there any way I can speed this up? In debug mode, my webpage takes 116 seconds to load versus 15 seconds if I start the project without debugging. I have set trace statements and identified that ~100 of the 116 seconds is spent in my DbContext.SaveChanges method when in debug mode. Running the project without debugging only 7 seconds in spent in the same section. Let me know in the

Adding and updating entities with Entity Framework

谁都会走 提交于 2019-12-09 04:24:43
问题 In my last project I have used Entity Framework 5 Code First. I completed my project but had a lot of pain during the development process. I tried to explain my pain below: I had several data classes in my data access logic layer like Product, ProductCategory, Order, Company, Manufacturer etc... Each class has some references to some other classes. For example, a Product instance has a ProductCategory property. Inside Add and Update methods of my Data Access Object classes I set the states of

DbContext.Entry attaching Entity

为君一笑 提交于 2019-12-08 22:10:20
问题 From my research, I read that calling DbContext.Entry(someEntity) would automatically attached the entity to the context. However, when I do this I find that the entity's state is detached. Can anyone shed some light on this and how the DbContect.Entry works. I'm using EF 5.0 Thanks. 回答1: If you're wanting to attach an object, what you actually want is DbSet.Attach. DbContext.Entry is only giving you information about the entity, and allows you to change the state if it's already been

How to enable cascading delete in Edmx Designer on many to many relation

混江龙づ霸主 提交于 2019-12-08 21:11:16
问题 I am using VS2012 and the Entity designer to generate both the database and the models. I have a very basic scenario of Table1 to Table1and2JoinTable to Table2. Something like Students, Classes, StudentClasses. You can have many students in many classes. I would like to have a cascading delete. So if you delete a student any rows in the StudentClass join table are deleted for that student id. Same for deleting a class any rows in the StudentClass are deleted for that class id. After setting

Entity Framework Migrations with Multiple Web Config Transforms

孤人 提交于 2019-12-08 19:49:40
问题 I have created an ASP.NET MVC 4 project in Visual Studio 2010 using Entity Framework 5 with migrations enabled. I have multiple web config files for different environments (Debug, Staging, Release) which will specify different database connectionStrings depending on the environment. How do I handle migrations using the Update-Database command from the Package Manager Console with the multiple config files? Each time I run this command, it defaults to the main Web.config connection string.