ef-code-first

configuring one to one relationship in asp.net identity

南楼画角 提交于 2019-12-12 02:43:27
问题 this is my ApplicationUser class.I have added only one new property ---- public class ApplicationUser : IdentityUser { //public ApplicationUser() //{ // UserProfileInfo = new UserProfileInfo { ImageSize = 0, FileName = null, ImageData = 0 }; //} public string HomeTown { get; set; } public virtual UserProfileInfo UserProfileInfo { get; set; } and this is my userProfileInfo class where i want to save every user's profile pic after they have completed the registration---- public class

Entity Framework: Fetch multiple collections with filters applied

╄→尐↘猪︶ㄣ 提交于 2019-12-12 02:37:33
问题 Giving the next model: public class User{ public int IdUser { get; set;} public virtual ICollection<Project> Projects { get; set;} public virtual ICollection<Exam> Exams { get; set;} } public class Project{ public int IdProject { get; set;} public bool Current { get; set;} public virtual User { get; set;} } public class Exam{ public int IdExam { get; set;} public int score { get; set;} public virtual User { get; set;} } I need to get the projects with current=true and exams with score greater

Entity Framework 6 (EF6) code first migrations with models in separate project

假如想象 提交于 2019-12-12 02:06:05
问题 Using EF6 code-first migrations, I am able to successfully save models and create new migrations for them. However, my DbContext class is in a Sharp.Data project, the actual (Sql CE) database lives under the Sharp.Server project bin folder, and my models live in a Sharp.Common project. When I run add-migration -ProjectName Sharp.Data Migration3 (pointing to Sharp.Data as that is where the DbContext is), it successfully runs and identifies changes made to the models in the Sharp.Common project

Inner Join Between Many to Many Relationship Models

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:58:51
问题 I have two model like below that are configured as many to many relationship: public class Permission { public int PermissionId { get; set; } public string PermissionName { get; set; } public virtual List<Role> Roles { get; set; } } public class Role { public int RoleId { get; set; } public string Name { get; set; } public string ID { get; set; } public virtual List<Permission> Permissions { get; set; } } I want to do an Inner Join with Linq. I can do that easily in SQL since the join table

Entity Framework Code First Update Does Not Update Foreign Key

走远了吗. 提交于 2019-12-12 01:53:45
问题 I'm using EF 4.1 Code First. I have an entity defined with a property like this: public class Publication { // other stuff public virtual MailoutTemplate Template { get; set; } } I've configured this foreign key using fluent style like so: modelBuilder.Entity<Publication>() .HasOptional(p => p.Template) .WithMany() .Map(p => p.MapKey("MailoutTemplateID")); I have an MVC form handler with some code in it that looks like this: public void Handle(PublicationEditViewModel publicationEditViewModel

Entity Framework code first relationships and navigation property?

浪尽此生 提交于 2019-12-12 01:52:53
问题 i have the following classes public class Subject{ public int SubjectId { get; set; } public String SubjectName { get; set; } public String SubjectCategory { get; set; } } public class QuestionDescriptor { public int QuestionDescriptorId { get; set; } public String QuestionText { get; set; } public String Answer { get; set; } public int SubjectId { get; set; } public virtual Subject Subject { get; set; } } i have configured it using the following code ,i want that a Subject can have many

EF 5 Code First DbMigration automation

江枫思渺然 提交于 2019-12-12 01:45:31
问题 I'm using EF 5 with the Code First Approach. I'm having trouble setting the default DateTime value of a column to a (getdateutc()) What I want to do is have EF set up tables with this value speficied, and the only way I've found that it's possible is to use DbMigrations (Up and Down methods). Are the any other ways ? I have a base class looking like this public abstract class BASE_AUDITED : BASE { [IgnoreDataMember, IgnoreMap] public DateTime Created { get; set; } [IgnoreDataMember, IgnoreMap

There is no store type corresponding to the conceptual side type 'Geography' of primitive type 'Geography'

こ雲淡風輕ζ 提交于 2019-12-12 01:38:52
问题 This error occurs on a pretty straightforward MVC 5 site using Entity Framework 6 in a code first implementation. Several of the models use System.Data.Entity.Spatial.DbGeography like the following model. using System; using System.ComponentModel.DataAnnotations; using System.Data.Entity.Spatial; namespace ProjectName.Models { public class PostalCode { [Key] [MaxLength(10)] public string PostalCodeValue { get; set; } public int Country { get; set; } [MaxLength(2)] public string StateAbbr {

EF Code First: One-to-One One-way Relationship

怎甘沉沦 提交于 2019-12-12 01:26:33
问题 I regularly have the following structure: MyClass public virtual ICollection<Version> Versions { get; set; } public virtual Version CurrentVersion { get; set; } That is, there is a list of stuff, and some class both points to that list, and one specific item in that list - either the current version of many versions, the next upcoming event in a list of events, etc. In my schema what I'd like to end up with is a Foreign Key pointing from Version to MyClass - that much works out properly. But

LINQ - outer join to parent class in EF code first

£可爱£侵袭症+ 提交于 2019-12-12 01:23:50
问题 I am missing something fundamental here I believe. I have the following EF code-first entities: Company and Modem. A company can have a list of modems. public class Company { public int ID { get; set; } ... public virtual ICollection<Modem> Modems { get; set:} } public class Modem { public int ID { get; set; } ... } This generates a column Company_ID as a foreign key, on the Modem table. I want to return all modems, with their company ID, if available. In SQL I would do the following : select