entity-framework-4.1

Table Mapping problem

时光总嘲笑我的痴心妄想 提交于 2020-01-13 06:59:07
问题 I am using entity framework 4 in my current project, to read data from several table. Compare using ADO.net, it EF is very easy, with simple code that can do lots of work or me. But there is one problem... e,g there is and exiting table call Table "MTable" i only want to query two column from this table, however this table is share with other two ppl who are also working on it. they might add column or modify constrains on this table. Only one thing i am sure is that, the two column i want to

How to perform CRUD with Entity Framework Code-First?

僤鯓⒐⒋嵵緔 提交于 2020-01-12 21:21:48
问题 I am having a really hard time updating and deleting many to many relationships with EF Code-first. I have a fairly simple Model: public class Issue { [Key] public int IssueId { get; set; } public int Number { get; set; } public string Title { get; set; } public DateTime Date { get; set; } public virtual ICollection<Creator> Creators { get; set; } } public class Creator { [Key] public int CreatorId { get; set; } public string FirstName { get; set; } public string MiddleName { get; set; }

What is the difference between that various data templates microsoft provides?

喜夏-厌秋 提交于 2020-01-12 09:53:09
问题 Note: This is not about the difference between Database first, Model first, and Code first. Microsoft has a number of tools to simplify using DbContext. Unfortunately, there seems to be almost no description and also no documentation on what they are, much less what they do. What is the difference between: Entity Framework Power Tools CTP1 ADO.NET C# DbContext Generator ADO.NET C# POCO Entity Generator 回答1: I don't usually answer my own questions, but here is what I figured out: The

Executing stored procedures from a DbContext

*爱你&永不变心* 提交于 2020-01-12 07:31:49
问题 I have two simple stored procedures in SqlServer: SetData(@id int, @data varchar(10)) GetData(@id int) . GetData currently returns a single-row, single-column result set, but I could change it to be a proper function if needed. What would be the best way to execute these from a DbContext instance? If possible, I'd like to avoid having to do my own connection state management and/or exposing EF-specific types. I started by retrieving the ObjectContext and looking at the Execute* functions, but

Entity Framework Code First and Classes that Implement IList<T>

谁说我不能喝 提交于 2020-01-11 12:09:10
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected

Entity Framework Code First and Classes that Implement IList<T>

泄露秘密 提交于 2020-01-11 12:09:05
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected

Mapping many to many relationship

元气小坏坏 提交于 2020-01-11 10:27:07
问题 I am have some trouble getting Entity Framework to handle a many to many relationship in my data schema. Here is my model: public class User { public int UserId { get; set; } public int Username { get; set; } public IEnumerable<Customer> Customers { get; set; } ... } public class Customer { public int CustomerId { get; set; } ... } public class CustomerUser { public int CustomerUserId { get; set; } public int CustomerId { get; set; } public int UserId { get; set; } public DateTime

Entity Framework 4.1 DatabaseGeneratedOption.Identity Performance

本秂侑毒 提交于 2020-01-11 08:01:30
问题 I currently working on a application that use Entity Framework 4.1 (code first) and SQL Server CE 4.0. One of the new things I really like from SQL Server CE 4.0 are the computed values. But I have some performance problem while importing old data into my new data store system (around 50000 entries). This is my second implementation for this. The first version used Entity Framework 4.0 and SQL Server CE 3.5. But there is a huge performance difference between these implementations. The code

Cant Add controller which uses Class which is inherited from other class

▼魔方 西西 提交于 2020-01-11 06:45:26
问题 I'm using Entity Framework and MVC3, and my problem is that I can't scaffold Controllers if the class inherits from another Class. Example: This is Base Class using System; using System.Collections.Generic; namespace CRMEntities { public partial class Company { public int Id { get; set; } } } This is Lead Class (Child) using System; using System.Collections.Generic; namespace CRMEntities { public partial class Lead : Company { public Lead() { this.Status = 1; this.IsQualified = false; }

Code First vs. Database First

一个人想着一个人 提交于 2020-01-10 09:38:11
问题 I created an Entity Framework model based on an existing database, then generated the POCO entities from the model. The connection string in my web.config isn't Entity Framework, it's just the standard connection string (it's missing the CSDL, SSDL, MSL references). I can compile my application, but when I run I get this error: Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database