entity-framework-4.1

view generated SQL for Entity Framewok SaveChanges command in Visual studio?

折月煮酒 提交于 2019-11-30 03:10:52
问题 I can see the SQL generated by Entity Framework for select operations in Visual studio, but not for insert, update and delete. how can I see the SQL generated for "DataContext.SaveChanges" command in Visual studio while debugging? 回答1: If you have visual studio ultimate you can see the updates and inserts in intellitrace. Just put a breakpoint right after SaveChanges is called. http://www.youtube.com/watch?v=fLBpZNXs-Lw If you are using it on a web project you could also use mini-profiler.

Create sql server compact file in appdata folder

主宰稳场 提交于 2019-11-30 03:03:20
问题 I am developing a simple piece of software which uses Entity Framework code first and sql server compact 4. At the moment this setup works. Entity framework creates the sql server compact file if it doesn't yet exists. The path to the database is defined from within a connectionstring which is stored inside the app.config file. It is build up like this: <connectionStrings> <add name="DataContext" connectionString="Data source=Database.sdf;" providerName="System.Data.SqlServerCe.4.0"/> <

The type or namespace name 'Entity' does not exist in the namespace 'System.Data'

冷暖自知 提交于 2019-11-30 03:02:31
I'm using WS class and it gave me error when I run the application: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' I have a reference to the System.Data; and to System.Data.Entity; But no changes. I keep getting the error. I have also in the web.config the line: <compilation debug ="true" targetFramework="4.0"/> Right-click on the Solution from the Visual Studio Solution Explorer click the Manage Nuget packages for solution and install the EntityFramework Hi this post is very misleading, if your reading this 2 years on. With using EF6 and .net 4.5.1 in VS

Conflicting changes to the role x of the relationship y have been detected

馋奶兔 提交于 2019-11-30 02:47:24
I am having the exception Conflicting changes to the role x of the relationship y have been detected. Every time I add my entity to my context Database.MyEntitys.Add(MyEntity); The class MyEntity contain this property : public virtual ICollection<DetailInfo> Group { get; set; } The DetailInfo class is pretty simple: public class DetailInfo:BaseEntity { public virtual Detail Detail { get; set; } public decimal Total { get; set; } public virtual MyEntity MyEntity { get; set; } } The DatabaseContext is also simple: public class MyEntityConfiguration : EntityTypeConfiguration<MyEntity> { public

Creating BiDirectional One - One relationship in Entity Framework 4.1 Code First

有些话、适合烂在心里 提交于 2019-11-30 02:45:02
I want to created Bi-Directional One-One relationship between two entities using EF Code First. I have trouble with the following code. What do you think I should do? public class User { public string ID { get; set; } public string LastName { get; set; } public string Password { get; set; } public string FirstName { get; set; } public int ProfileID { get; set; } public Profile Profile { get; set; } } public class Profile { public int UserID { get; set; } public User User { get; set; } public int ProfileID { get; set; } public string ProfileName { get; set; } public DateTime CreateDate { get;

How to represent Bridge table in Entity Framework Code First

爷,独闯天下 提交于 2019-11-30 02:33:56
问题 I am trying to find out how I can represent a bridge table between two entities (many to many relation) I'm Using Entity Framework Code First Student: StudentID int PK StudentName VARCHAR(50) Class: ClassID int PK ClassName VARCHAR(50) StudentClass: StudentID INT PK ClassID INT PK What is the best Class Structure should i Use to represent it in Entity Framework Code First and how can i select from the bridge table and insert in it. Should I represent the classes it like this: public class

Mapping association tables in EF 4.1 code first

给你一囗甜甜゛ 提交于 2019-11-30 02:29:06
I'm not sure how to map the following tables below in EF 4.1 code first and what objects I need representing the tables. How would I retrieve a list of the product's specifications? I currently only have a Product class. Products Table: Id Name IsActive ProductSpecification Table: ProductId SpecificationId Specifications Table: Id Name IsActive ProductSpecifications is an association table. I also have the following defined in my context class: public DbSet<Product> Products { get; set; } EDIT Please see my updated original post. I changed the Id of the Products and Specifications tables. In

EF code-first PluralizingTableNameConvention for ONE DbSet

*爱你&永不变心* 提交于 2019-11-30 01:53:43
问题 How do I toggle this convention PluralizingTableNameConvention for only a single table/DbSet? As far as I can tell, I can only do this to all the DbSets for a given DbContext 回答1: If you have only one entity which is mapped to a table that is not pluralizeed then you can remove the PluralizingTableNameConvention and manually configure the table name of the entity. public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating

DbContext ChangeTracking kills performance?

偶尔善良 提交于 2019-11-30 01:26:20
I am in the process of upgrading an application from EF1 to EF4.1 I created a DbContext and a set of POCOs using the "ADO.NET DbContext Generator" templates. When I query the generated DbContext the database part of the query takes 4ms to execute (validated with EF Profiler). And then it takes the context about 40 seconds (in words: FORTY!) to do whatever it does before it returns the result to the application. EF1 handles the same query in less than 2 seconds. Turning off AutoDetectChanges, LazyLoading and ProxyGeneration wins me 2-3 seconds. When I use the AsNoTracking() extension method I

Why does Entity Framework return null List<> instead of empty ones?

ぃ、小莉子 提交于 2019-11-30 00:13:41
问题 I'm pretty new in the ASP .NET MVC world. Maybe, that's the reason I can't explain to myself the cause of what is, for me, an annoying problem. I have one class with One-To-Many relashionship. class MyClass{ public List<OtherClass> otherClasses {get;set;} } When I'm persisting one instance of this class, I fill it's relationship with an empty List<> MyClass myClass = new MyClass(){ otherClasses = new List<OtherClass>() } context.myClass.Add(myClass); The problem is that, when I try to