entity-framework-4.1

Linq to Entity Framework return a list of parents with only a subset or empty collection of children

霸气de小男生 提交于 2020-01-04 10:43:43
问题 Given a list of parents and their children I want to return a list of all parents and only their male children. This is trivial in a sql query. The problem I have is with Linq to EF I cannot seem to get the query to work in any fashion. Due to EF limitations I cannot do an include to ensure the return of the Children I want. How do I accomplish the below sql in LINQ to return my Parent Entity with Children Collection with only males or Empty collections ignoring all of the female records? SQL

Linq to Entity Framework return a list of parents with only a subset or empty collection of children

六月ゝ 毕业季﹏ 提交于 2020-01-04 10:42:11
问题 Given a list of parents and their children I want to return a list of all parents and only their male children. This is trivial in a sql query. The problem I have is with Linq to EF I cannot seem to get the query to work in any fashion. Due to EF limitations I cannot do an include to ensure the return of the Children I want. How do I accomplish the below sql in LINQ to return my Parent Entity with Children Collection with only males or Empty collections ignoring all of the female records? SQL

“Hide” column from database, but not View in Entity Framework

眉间皱痕 提交于 2020-01-04 10:39:50
问题 I am using a code-first methodology. I have created my own user model and membership provider. My model has some of the following fields: [Table("mytable")] public class MyUser { [Key] public int UserId { get; set; } // Auto generated [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Email address")] public string Email { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display

“Hide” column from database, but not View in Entity Framework

独自空忆成欢 提交于 2020-01-04 10:39:08
问题 I am using a code-first methodology. I have created my own user model and membership provider. My model has some of the following fields: [Table("mytable")] public class MyUser { [Key] public int UserId { get; set; } // Auto generated [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Email address")] public string Email { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display

ASP.Net MVC 3, Complex Objects and Lazy Loading

爷,独闯天下 提交于 2020-01-04 06:23:08
问题 First of all, I am new to ASP.Net MVC 3, and I am also using EF 4.1. I have a complex object, something similar to let's say a Product object containing a Category object. So we have Product.CategoryId, Product.Category and some extra properties. I also have a form to create products with a dropdown list to select the category. In my controller, after the product has been created, I need to have access to some property of the Category to perform some extra stuff. However, although Product

EF4.1 DbSet vs. EF4 ObjectContext and Unit Testing

独自空忆成欢 提交于 2020-01-04 05:21:19
问题 I currently have a project I've started with EF4, and am going back and adding in unit testing after the fact. I am using the EF4 POCO T4 templates with my model (database) first context. I am using generic repositories for my DAC logic, and unit of work pattern for persistence. However, I'm running into some issues understanding how to mock up the ObjectContext/ObjectSet. I looked at using the FakeObjectSet<T> sample from this article, but it still leaves a few things out, such as auto

EF4.1 DbSet vs. EF4 ObjectContext and Unit Testing

让人想犯罪 __ 提交于 2020-01-04 05:21:14
问题 I currently have a project I've started with EF4, and am going back and adding in unit testing after the fact. I am using the EF4 POCO T4 templates with my model (database) first context. I am using generic repositories for my DAC logic, and unit of work pattern for persistence. However, I'm running into some issues understanding how to mock up the ObjectContext/ObjectSet. I looked at using the FakeObjectSet<T> sample from this article, but it still leaves a few things out, such as auto

Entity SQLCE Can't find connection string in app.config file

*爱你&永不变心* 提交于 2020-01-04 04:14:27
问题 I've been getting this error when I try and use my model container: No connection string named 'PFModelContainer' could be found in the application config file. I have my edmx file in a separate project. I checked the app.config file and my model was there, and I also put it in my main project app.config file. Still doesn't work. Here's the connection string: <connectionStrings> <add name="PFModelContainer" connectionString="metadata=res://*/PFModel.csdl|res: //*/PFModel.ssdl|res://*/PFModel

What are the pros and cons of one master base table which all entities inherit from?

落爺英雄遲暮 提交于 2020-01-04 02:56:10
问题 I am using Entity Framework Database first approach to create my domain model. I am considering creating a base table EntityBase with the base properties in: PK CreatedDate CreatedBy ModifiedDate ModifiedBy etc. Using Table Per Type inheritance I will end up with a single table in the Database linked to all other entity tables: EntityBase { EntityBase_PK => Identity PK CreatedDate CreatedBy ModifiedDate ModifiedBy } DerivedEntity1 { DerivedEntity1_PK => FK relationship to EntityBase on

EF Code First Custom Collections

*爱你&永不变心* 提交于 2020-01-03 08:45:13
问题 When creating code first collections can you implement a custom class that implements ICollection. The code below is conceptual not actual public class Product { public int ProductId { get; set; } public string Name { get; set; } public Category Category { get; set; } } public class Category { public int CategoryId { get; set; } public string Name { get; set; } //Want to Avoid This public ICollection<Product> Products { get; set; } //Use his instead of above public ProductList