navigation-properties

Navigation Properties as Primary Keys

会有一股神秘感。 提交于 2019-12-11 00:54:15
问题 I'm using EF 6 with MVC 5. I have a class defined as follows: public class ConEdSignup { [Key, Column(Order = 0)] public virtual ApplicationUser Attendee { get; set; } [Key, Column(Order = 1)] public virtual ConEdSession ConEdSession { get; set; } [Required] public DateTime SignupTime { get; set; } [Required] public bool Attended { get; set; } } This is basically a link table for a many-to-many relationship where I have additional properties about that relationship. When I try to create a

Using navigation properties in entity framework code first

你。 提交于 2019-12-10 13:13:39
问题 Context: Code First, Entity Framework 4.3.1; User ---- Topic, 1 to Many relation; User with public virtual ICollection<Topic> CreatedTopics Navigation Property(Lazy Loading); Topic with public virtual User Creator Navigation Property; DataServiceController : DbDataController<DefaultDbContext> , Web API beta, ASP.NET MVC 4 Beta , Single Page Application; System.Json for Json serialization; Web API Action: public IQueryable<Topic> GetTopics() { // return DbContext.Topics; // OK return DbContext

Can I lazy load a navigation property by delegating to a stored procedure in EF?

拥有回忆 提交于 2019-12-10 03:11:07
问题 I have the following customer class: public class Customer { public long Id { get; set; } public virtual ICollection<Order> Orders { get; set; } } My database has Customers and Orders tables, but no foreign key relationships. Orders for a customer are obtained using a stored procedure that takes the customer ID and returns the order rows. I can't modify the database. I know how to call the stored procedure from Entity Framework, but, is it possible to configure the DbContext using the fluent

Ignore Properties in OnModelCreating

泄露秘密 提交于 2019-12-06 12:34:09
问题 I'm attempting to use Bounded (Db) Contexts in Entity Framework 5.0, and I'm having problems excluding a property from one of the classes included in a specific context. Here is the information (I'll shorten for brevity) BaseContext.cs public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } protected BaseContext() : base("name=Development") { } } IContext.cs public interface IContext : IDisposable { int

Can I lazy load a navigation property by delegating to a stored procedure in EF?

你说的曾经没有我的故事 提交于 2019-12-05 03:36:13
I have the following customer class: public class Customer { public long Id { get; set; } public virtual ICollection<Order> Orders { get; set; } } My database has Customers and Orders tables, but no foreign key relationships. Orders for a customer are obtained using a stored procedure that takes the customer ID and returns the order rows. I can't modify the database. I know how to call the stored procedure from Entity Framework, but, is it possible to configure the DbContext using the fluent API so that accessing the Orders collection of a customer object would lazy load the entities via a

Entity Framework Core: private or protected navigation properties

血红的双手。 提交于 2019-12-05 02:54:10
Is it somehow possible to define navigation properties in EFCore with private or protected access level to make this kind of code work: class Model { public int Id { get; set; } virtual protected ICollection<ChildModel> childs { get; set; } } You have two options, using type/string inside the model builder. modelBuilder.Entity<Model>(c => c.HasMany(typeof(Model), "childs") .WithOne("parent") .HasForeignKey("elementID"); ); Not 100% sure it works with private properties, but it should. Update: Refactoring-safe version modelBuilder.Entity<Model>(c => c.HasMany(typeof(Model), nameof(Model.childs)

Including navigation properties from Entity Framework TPH classes

寵の児 提交于 2019-12-05 02:19:06
问题 I've got an EF hierarchy that (dramatically simplified) looks something like this: class Room { EntityCollection<Session> Sessions; } class Session { EntityCollection<Whiteboard> Whiteboards; EntityReference Room; } class Whiteboard { EntityCollection<WhiteboardShape> WhiteboardShapes; EntityReference Session; } abstract class WhiteboardShape { EntityReference Whiteboard; } class WhiteboardShapeEllipse : WhiteboardShape { } class WhiteboardShapePolyline { WhiteboardShape { EntityCollection

Ignore Properties in OnModelCreating

怎甘沉沦 提交于 2019-12-04 17:12:35
I'm attempting to use Bounded (Db) Contexts in Entity Framework 5.0, and I'm having problems excluding a property from one of the classes included in a specific context. Here is the information (I'll shorten for brevity) BaseContext.cs public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } protected BaseContext() : base("name=Development") { } } IContext.cs public interface IContext : IDisposable { int SaveChanges(); void SetModified(object entity); void SetAdded(object entity); } ISuiteContext.cs public

Can you exclude reverse navigation properties in EF when eager loading?

拜拜、爱过 提交于 2019-12-04 03:28:44
问题 When I use the .Include syntax in EF6, reverse navigation properties are always loaded. Is there a way to turn that off? Here is a sample query. private static IQueryable<Account> GetAccountsEager(this IRepository<Account> repository) { return repository .Queryable() .Include(e => e.AccountLocations .Select(l => l.Address.City.State.Country)); } This gives me the account's collection of AccountLocations. However, the Address' city has this reverse navigation property on it: public virtual

Entity Framework (Database-First) multiple relations to same table naming conventions control

≯℡__Kan透↙ 提交于 2019-12-04 00:00:39
Let's suppose that we have this situation: Tables in database: Country (id, country_name), Person (id, login), CountryManager (id_country, id_person), CountryStakeholder (id_country, id_person) If we had to create the model from the database, using Entity Framework Database-First, in VS we'd have a class like this: class Country { int id; string country_name; virtual ICollection<Person> Person1; // Navigation Properties virtual ICollection<Person> Person2; // ---------||---------- } I've simplified the code a lot, but hopefully you got the point. Seems that when Entity Framework deals with