ef-code-first

PredicateBuilder, build predicate over 2 tables using EF

点点圈 提交于 2019-12-11 08:24:14
问题 I've got a complex problem, but the explanation of it is even more complex (I think). But I'll give it a try anyway, if it's not clear, please ask me to elaborate. I have a table called UserService . A service is whatever a user offers, for example a band that plays in a cafe. Another one is DJ and room. Here is what the table looks like: [Table("UserService")] public class UserService { public int Id { get; set; } public string UserId { get; set; } public string Name { get; set; } public

Bi-directional relationships in Entity Framework (Code First)

回眸只為那壹抹淺笑 提交于 2019-12-11 07:54:19
问题 I have a question about best practice in terms of Code First EF. I have two classes User.cs and Team.cs: public class Team() { [Key] public int TeamId{get;set;} public string TeamName {get;set;} public virtual User TeamLead {get;set;} public virtual User Manager {get;set;} } public class User { public int UserId {get;set;} public string FullName {get;set;} } Each User has one Team. A team needs a TeamLead and a Manager. How do I create the bi-directional relationship in Code First EF? I have

How to remove Many to Many auto generated table with Entity Framework Code First

我怕爱的太早我们不能终老 提交于 2019-12-11 07:53:37
问题 I have 3 Entities Product , Supplier & Contract , Product & Supplier each have as reference a Collection of each other which creates a ProductSupplier Table. To add an extra property on this Many to Many relation i have created a 3rd Entity ProductForSupplier wich holds 1 Product, 1 Supplier and a extra string Property ProductNumber. In addition i have created another Entity ProductSupplierForContract which holds a ProductForSupplier & a Contract. When i seed some data for test i can observe

EF Code First Many-to-Many not working

两盒软妹~` 提交于 2019-12-11 07:37:32
问题 Using the Entity Framework Code First paradigm I have defined the following objects and relationships as part of an ASP.Net MVC3 application. The problem is the many-to-many relationship between the Photo and Gallery objects is not working properly. Currently a gallery can contain many photos - this is correct. But a photo can only be associated with one Gallery - this is incorrect. I want a photo to be able to be in many galleries. If I add a photo to a gallery when it is already associated

How does .Include() Work?

青春壹個敷衍的年華 提交于 2019-12-11 07:34:02
问题 Hi I created a database using an Entities diagram in visual studio where i added navigation properties. I created it using this tutorial http://geekswithblogs.net/danemorgridge/archive/2009/10/29/using-visual-studio-2010-beta-2-to-do-entity-framework.aspx It looks like this User Table IdUser Name IdAccount 1 Ron 2 2 Carl 1 Navigation property: Account (one to one relation) Account table IdAccount Amount 1 50 2 30 Navigation property: Account (one to one relation Notice that user1 has account

Entity not updating using Code-First approach

天涯浪子 提交于 2019-12-11 07:26:41
问题 I have this class that I use for DB operations: public class EntityService<TEntity> : IRepository<TEntity> where TEntity : BaseModel { ApplicationDbContext _context; private DbSet<TEntity> _entities; public EntityService() { _context = new ApplicationDbContext(); } public virtual void Update(TEntity entity) { if (entity == null) throw new ArgumentNullException(nameof(entity)); try { var dbEnt = _context.Set<TEntity>().Where(c => c.Id == entity.Id).First(); dbEnt = entity; dbEnt.UpdatedBy =

Upgrading to MvcMiniProfiler 1.9 from 1.7 .NET MVC3 and EF Code First

淺唱寂寞╮ 提交于 2019-12-11 07:16:19
问题 Today I've dropped back into a project that I haven't been working with for the past month or so. I had this project configured using MiniProfiler 1.7 and all was well in the world. It profiled my DB calls and the view performance as well. I decided to upgrade to 1.9 and I've run into a few speed bumps. Now, I've worked through most of the issues at this point. The only thing that seems "wrong" is DB profiling. I'm getting dropped a yellow screen of death with the following error: A null was

The number of columns specified must match the number of primary key columns EF

最后都变了- 提交于 2019-12-11 06:54:00
问题 I have two tables having composite pk's. The pk of TABLE1 goes into TABLE2 and they have a one to one optional relationship i.e TABLE1 may have 1 TABLE2 or 0 TABLE2. I get the following exception on model creation when I insert data. The specified association foreign key columns 'third_table_id, fourth_table_id' are invalid. The number of columns specified must match the number of primary key columns. Any help would be appreciated. The pk's of the table 1 come from table 3 I have defined the

Using Entity Framework 4.1, how do I configure one to many relationship with composite keys using different field names?

江枫思渺然 提交于 2019-12-11 06:48:52
问题 I have two tables: DeptMaster and LaborMaster where one DeptMaster has many LaborMasters. These are legacy tables from an old database so they don't follow Code First naming conventions. They both use composite keys but with different column names in each table. The classes have navigational properties as well. I would prefer mapping them with attributes but please show me that method if possible but also the fluent way. [Table("DeptMaster"), Schema="HR"] public partial class DeptMaster {

Why doesn't DropCreateDatabaseAlways drop the database when the model changes?

喜你入骨 提交于 2019-12-11 06:37:58
问题 I have a model with one entity: namespace TestMigration { public class BlogContext : DbContext { public DbSet<Blog> Blogs { get; set; } } public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public int FollowersCount { get; set; } //public int BloggerAge { get; set; } } } The Initializer class: public class DataInitializer : DropCreateDatabaseAlways<BlogContext> { protected override void Seed(BlogContext context) { var blogs =