navigation-properties

How to filter by fields from navigation properties in Entity Framework?

烈酒焚心 提交于 2020-01-05 08:52:24
问题 I have classes like: public class ProductInCategory { public Guid Guid { get; set; } public long ProductID { get; set; } public long ProductCategoryID { get; set; } public virtual Product Product { get; set; } public virtual ProductCategory ProductCategory { get; set; } } public class Product { public virtual ICollection<ProductInCategory> ProductsInCategories { get; set; } // and other fields and navigation properties not important for this example } And now I want to execute query which

When declaring relationship is not necessary in Entity Framework 6?

喜欢而已 提交于 2020-01-05 08:08:10
问题 In EF6 we have two ways to declare relationship between two tables: Annotations Attributes Fluent API Today (by accident) I removed one relationship between two tables and everything kept working well. I was very surprised because there was no way EF would know how those two tables are connected. Tables look like that: [Table("item")] public class Item { public Item() { ItemNotes = new HashSet<ItemNote>(); } [Key] [Column("itemID", TypeName = "int")] [DatabaseGenerated(DatabaseGeneratedOption

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

喜夏-厌秋 提交于 2020-01-01 07:33:06
问题 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

Create incident in dynamics crm using api in php

时光怂恿深爱的人放手 提交于 2019-12-25 04:57:06
问题 Im trying to create case in dynamics CRM using php.For that I can see that title,description and customer is required.So that I tried below code: $authHeader = 'Authorization:' . $type.' '.$access_token; //Request for incidents $data = array("title"=>"api_incident_title", "description" =>"api_incident_description", "primaryContactid" =>"https://vonageholdings.crm.dynamics.com/api/data/v8.0/accounts(ebaf25a6-f131-e611-80f8-c4346bac3990)" ); //URL $url ='https://vonageholdings.crm.dynamics.com

How can I include more than one level deep in a LINQ query?

旧城冷巷雨未停 提交于 2019-12-25 02:32:47
问题 I have three SQL tables that are represented by classes and I would like to have Entity Framework 6 join these tables so I get all the details of the Exam , Test and UserTest tables where the UserTest.UserID is 0 or X . I have already set up a respository and this works for simple queries however I am unable to join the UserTest class in the LINQ at the bottom of the question. Here's my classes: public class Exam { public int ExamId { get; set; } public int SubjectId { get; set; } public

Entity framework core: How to test navigation propery loading when use in-memory datastore

旧街凉风 提交于 2019-12-23 13:24:31
问题 There is an interesting feature exists in entity framework core: Entity Framework Core will automatically fix-up navigation properties to any other entities that were previously loaded into the context instance. So even if you don't explicitly include the data for a navigation property, the property may still be populated if some or all of the related entities were previously loaded. This is nice in some cases. However at the current moment I'm trying to modelling many-to-many relation with

Entity Framework Lazy Loading with generic repository

▼魔方 西西 提交于 2019-12-23 03:31:46
问题 My current project uses a generic repository interface, thus: public interface IDataSource : IDisposable { void Add<T>(T newItem) where T : EntityBase; T Get<T>(Guid id) where T : EntityBase; T Get<T>(Expression<Func<T, bool>> predicate) where T : EntityBase; IQueryable<T> GetAll<T>(Expression<Func<T, bool>> predicate = null) where T : EntityBase; int Count<T>(Expression<Func<T, bool>> predicate = null) where T : EntityBase; bool Any<T>(Expression<Func<T, bool>> predicate = null) where T :

Entity Framework Core: private or protected navigation properties

為{幸葍}努か 提交于 2019-12-22 04:07:07
问题 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; } } 回答1: 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.

The declared type of navigation property XYZ is not compatible with the result of the specified navigation

浪子不回头ぞ 提交于 2019-12-22 01:07:23
问题 Hi There I have the following Model Template (Id,Name) UserBody (Id, name) EmployeeBody (Id, Name) I then Have a template mappers where i associate a template with one of many users and employess. TemplatesMaps (id, TemplateId, UserId, EmployeeId) userid and employeeId are nullable I need a TemplatesMaps to consist of 1 templateid mapping to many Userbody.id 's and many EmployeeBody.Id's Example Id TemplateId UserBodyId, EmployeeBodyId 1 1 1 Null 2 1 Null Null 3 2 4 Null 4 2 Null 5 MY Code is

.Skip().Take() on Entity Framework Navigation Properties is executing SELECT * on my SQL Server

家住魔仙堡 提交于 2019-12-20 09:45:01
问题 I have a method on my generated partial class like this: var pChildren = this.Children .Skip(skipRelated) .Take(takeRelated) .ToList(); When I look at my SQL Server, I can see the generated code is doing a SELECT *.* FROM Children This code is taken directly from my class, I have verified that the order of my Skip/Take is BEFORE my .ToList. If I remove the .ToList, that line is fast (and no SQL is sent to my DB), but the moment I try to foreach over the results, I get the same SQL sent to my