code-first

Which assembly should I place the compiled views for entity framework code first when context is in a separate project from the domain classes

纵饮孤独 提交于 2019-12-11 14:01:19
问题 In desperate need of help. I'm using entity framework code first and trying to follow Julie Lerman's suggestion about breaking out the context from the domain classes and I'm unable to get entity framework to recognize the compiled views. I've tried many things but the best so far is that I can get the constructor of the compiled views to be called but it still takes about 15 mins for the 1st query (about 329 entities and 600+ views created). This makes me think it is still having to create

Code first, working with relationships, seeding

社会主义新天地 提交于 2019-12-11 13:54:39
问题 I would like to simply create a relationship between two entities that already exists.. In my case I have an Album entity which might have multiple Genres(which also is a bunch of entities) My Album model looks like this: public class AlbumModel : IModel { public List<GenreModel> Genres { get; set; } public ArtistModel Artist { get; set; } public Guid Id { get; set; } public string Title { get; set; } public float Price { get; set; } public string ArtUrl { get; set; } } I then want to create

Entity Framework code first seems confused on my dbo table names after I tweaked the migration file

醉酒当歌 提交于 2019-12-11 12:56:47
问题 I've just begun using Entity Framework 5 (Code First Migrations). I think my issue may just be a given to someone that's worked with this a bit longer than I have (this is our first project giving it a go). I have 3 tables involved. One is a cross reference table. The gist of the classes is as follows: public class Person { //person properties public virtual List<Roles> Roles {get;set;} } public class Role { //Role properties public virtual List<Person> Persons {get;set;} } Adding a migration

EF Code First DbContext and Compiled Queries

北城以北 提交于 2019-12-11 12:54:19
问题 Has anybody heard if there is any word on whether we will have compiled queries with EF Code First DbContexts? Or, if it is already possible, and I am doing it wrong, can somebody point me in the right direction? It would seem Bing and Google don't have a lot of information on it yet. 回答1: The CTP4 had compiled query support, but it was removed in CTP5, vote it up if you want it back here: http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions

Entity Framework Table Per Hierarchy Inserting Multiple Id Columns

点点圈 提交于 2019-12-11 12:36:16
问题 I have seriously spent two work days trying to a TPH setup from Database First to Code first. The Error I get is Something like "Invalid Column Name Entity_EntityId/ Entity_Entity_Id1" I've drawn up a very basic reproduction of the issue like so: internal class Program { private static void Main(string[] args) { using (var context = new Context()) { var baseClass = new Base {Name = "Test"}; context.BaseClasses.Add(baseClass); context.SaveChanges(); var baseClasses = context.BaseClasses.ToList

How to prevent Code First from enabling foreign key constraint on a relationship?

耗尽温柔 提交于 2019-12-11 08:37:31
问题 I have two entities, User and Feedback, and there is one-to-many relationship between those with help of the username field. Feedback --> User -------- -------- username username However, sometimes feedback may code from an unregistered user, and Username field on Feedback will be Null. In that case, the addition of feedback will fail due to the foreign key constraint. How can I disable the enforcement of a foreign key constraint on a relationship declaratively or by means of the Fluent API?

Cannot Generate Database from Entity Framework 4.1 Codefirst With SQL Server 2005

痞子三分冷 提交于 2019-12-11 07:39:27
问题 I try to create database from entity framework code first follow with this tutorial http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part4-cs but I use SQL Server 2005 instead when SQLExpress but When I execute solution don't have anything create. What wrong with my code This is my code. Movie.cs public class Movie { public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public decimal Price { get;

EF4 CTP5, mapping different entities to the same (existing) table

痴心易碎 提交于 2019-12-11 05:22:17
问题 By code-first approach (but with an existing db schema), we are trying to map 2 different entities (Customer and Resource) to the same table. Both entities has the same keys and mapping. However, when running the app, we have a runtime error telling us that mysterious message: System.InvalidOperationException: Type 'Resource' cannot be mapped to table 'CLIENT' since type 'Customer' also maps to the same table and their primary key names don't match. Change either of the primary key property

Entity Framework code-first, one-to-zero-to-one and one-to-many relationship to same entity

让人想犯罪 __ 提交于 2019-12-11 04:51:53
问题 I'm creating a code-first database with v6.0 of the Entity Framework. I have an Organisation class and a related Location class defined in c# as follows: public class Organisation { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Location> Locations { get; set; } public int? HQLocationId { get; set; } public Location HQLocation { get; set; } } public class Location { public int Id { get; set; } public string Name { get; set; } public int OrganisationId

Entity Framework Many to Many Cascade Delete Issue

非 Y 不嫁゛ 提交于 2019-12-11 04:23:35
问题 Having a strange issue working on a code first EF project. I have the following entities: public class Booking { public Guid BookingId { get; set; } public virtual List<AccountingDocumentItem> AccountingDocumentItems { get; set; } } public class AccountingDocumentItem { public Guid AccountingDocumentItemId { get; set; } public virtual List<Employee> Employees { get; set; } public virtual List<Booking> Bookings { get; set; } } public class Employee { public Guid EmployeeId { get; set; } public