ef-code-first

Referencing to the EntityFramework.dll cause an run-time error in VS2010

…衆ロ難τιáo~ 提交于 2019-12-12 00:28:21
问题 [Updated] I have 2 projects in my solution. the first one is my DAL project(Class Library), and the second is a Windows Project(UI), my DAL Project referenced to EF 4.3.1 and worked normally, Recently I referenced my DAL project to EF6 , using Package Manager Console, by Update-Package EntityFramework command, in VS2010, after applying the recommended changes in EF official site, now the app.config of my DAL project include these lines: <configSections> <section name="entityFramework" type=

Is database recovery from EF model possible?

两盒软妹~` 提交于 2019-12-11 23:18:16
问题 I had a web service project, with a database integration of course :) I use Entity Framework, so I generated my EF model from my db (sql server express). Everything was okay till my computer got broke. I had my project files backed up so I recovered them. But I didn't have the db backup(shame). As far as I know there is this concept Code First , and what I am wondering is can I use it to regenerate my db? Otherwise I'll have to try getting the db from the old disk, or rewriting the whole db.

Why is one of my reference properties not being included when using LINQ to Entities Include()?

吃可爱长大的小学妹 提交于 2019-12-11 23:17:12
问题 I have the following property declarations and mappings (abridged classes): public class Consumer: AuditableEntity { public virtual Consumer Parent { get; set; } public virtual User User { get; set; } public virtual Role Role { get; set; } public virtual ICollection<Consumer> Consumers { get; set; } } public ConsumerMap() { HasRequired(t => t.Role) .WithMany(t => t.Consumers) .Map(a => a.MapKey("RoleId")) .WillCascadeOnDelete(false); HasRequired(t => t.User) .WithOptional(t => t.Consumer)

Entity Framework Code First wrapper or repository?

无人久伴 提交于 2019-12-11 23:06:01
问题 I've seen it mentioned sometimes that Repository Pattern is built into Entity Framework Code First via the DbSet and DbContext objects. However that leaves a few problems: 1) Injection - Hard to inject as there isn't a clear cut Interface 2) Mocking - Same as above 3) Multiple references to EnitityFramework.dll - Let's say I create my Code First in it's own assembly/project and then want to reference that in another place I also have to reference entityFramework.dll without some wrapper

how to perform -disconnected- delete in many-to-many relationships (Entity Framework Code First)

百般思念 提交于 2019-12-11 22:56:27
问题 I have the following code for adding a record to many-to-many relationship in a disconnected way. I wonder if it is possible to achieve a delete operation with disconnected approach. using (var db = new FMyDbContext()) { int selectedTeamId = Convert.ToInt32(lst_AllTeams.SelectedValue); Team myTeam = new Team() { TeamId = selectedTeamId }; int selectedCompId = Convert.ToInt32(grd_Competitions.SelectedValue.ToString()); Competition myComp = new Competition() { CompetitionId = selectedCompId };

Mvc code first style

你说的曾经没有我的故事 提交于 2019-12-11 22:42:29
问题 I made a simple mvc 3 web site. It's working fine but the database and classes are messy because I needed to make dropdownlists and I have no idea how to implement the drowdownlists using a different style. Here's how things look like: public class Departments { public int ID {get; set;} ... } public class Users { public int ID {get; set;} ... public Department Dept {get; set;} public List<Department> DeptList {get; set;} public string SelectedDept {get; set;} } then I used DropDownListFor

Can't get property names working with foreign keys in Code First

我只是一个虾纸丫 提交于 2019-12-11 21:41:35
问题 I have been supplied a DB, and I need to get Code First set up for it. I think I'm mostly done, the problem that I'm running into right now is I want to change some of the foreign key names in the entities to make a little more sense. Let's say I have two tables, Person and Location, that look like this: Person ------ PersonId int not null (PK) DefaultLocation int not null (FK) Location -------- LocationId int not null (PK) For the location entity, I think I've got it: public class Location {

Insert instead of update for history data?

爱⌒轻易说出口 提交于 2019-12-11 20:58:17
问题 I am using EF 6.1 Code First and want to track history data by using a model which (simplified) looks like this: public class Customer : IHistoryData<CustomerData> { public Guid ID { get; set; } public virtual ISet<CustomerData> Versions { get; set; } } public class CustomerData : HistoricalData { public string Name { get; set; } } public interface IHistoryData<T> where T : HistoricalData { ISet<T> Versions { get; set; } } public class HistoricalData { public int VersionID { get; set; }

Move my Code First Entity Framework created database to the Default Membership Provider database

筅森魡賤 提交于 2019-12-11 20:05:16
问题 I have an ASP.NET MVC3 application that I have built and it has two databases. One is in reference to the Default Membership Provider and was automatically created when I built the app. The other is a database I have named SchoolContext and I would like all the information within SchoolContext to be stored in the same database as all the data in Default Membership Provider. Here are my two connection strings: <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS

How to set up a complex many to many relationship in entity framework 4 code first

落爺英雄遲暮 提交于 2019-12-11 19:48:06
问题 I have a relatively complex relationship I need to set up between a User object and a lot of lookup tables. The user object is your run of the mill user model: public class Youth : IAuditInfo { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public Guid YouthGuid { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Address Address { get; set; } public DateTime CreatedDate { get; set; } public DateTime