entity-framework-6

DataContractSerializer with Multi-tiered data structures

瘦欲@ 提交于 2019-12-11 06:59:56
问题 I'm attempting to implement a DataContractSerializer to generate an XML file that represents our somewhat complicated object model. The root object has multiple ICollection properties, one of which has multiple ICollection properties, multiples of which have multiple ICollection properties... you get the idea. I decorated all my relevant classes with [DataContract(Name = "foo")] tags, read this question about using Include() , and started framing it out. As I put together the top layer, I

Entity Framework - only edmx without templates

自作多情 提交于 2019-12-11 06:51:08
问题 We would like to add only .EDMX files without corresponding .tt files for context and entities. There is multiple reasons for this, but long story short - we would like to be able to have .EDMX and be able to refresh it from DB when needed. Currently if I delete .tt files every time I "Update from DB" it will regenerate .tt files and entitites which we don't need. 回答1: If it's enough to have only the .edmx with two empty .tt files you can do that: Add the Entity Data Model (EF Designer from

Two foreign keys with same Navigation Property?

ε祈祈猫儿з 提交于 2019-12-11 06:46:33
问题 I am new to Entity Framework so I don't know much about it. Currently I am working on My College Project, in that Project I came across a problem where I have two foreign keys refers to the Same column in another table. how can I handle this situation. Is it necessary to create Navigation Property for Every Foreign key. And if I create another Navigaton property for ContactId then it is necessary to create another Navigation Property in User class like: public virtual ICollection<BlockedUser>

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 =

EF6.1 newsequentialid with ability to set value manually

£可爱£侵袭症+ 提交于 2019-12-11 06:37:38
问题 I'm new to EF(v6.1). Trying to use Code-First approach. I would like to have Id column to be generated on SQL server side ( newsequentialid() ), however with ability to override those values. My code: [Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } Which results in perfect SQL: [Id] [uniqueidentifier] NOT NULL DEFAULT (newsequentialid()) However EF simply ignores any value I would set to Id property and pass null to SQL. Essentially follwing

Entity Framework 6.2 very slow first startup and EFInteractiveViews

我们两清 提交于 2019-12-11 06:36:55
问题 this topic is already widely discussed on stackoverflow and many other blogs, reason to asking question is that i observe this topic was discussed in mostly 3 to 5 years old posts whereas we have EF 6.2 version now, and i expect this may have updates already (there are more reasons you will find in question. My application has at least 25 Models(Tables) with MySQL as database, models and relations are configured in OnModelCreating, web site is hosted on godaddy and i do not have good access

Entity Framework 6.X and one-to-one relationship

為{幸葍}努か 提交于 2019-12-11 06:29:33
问题 I have the following model: public partial class Driver { public string FirstName { get; set; } public string LastName { get; set; } public string Nickname { get; set; } public virtual AspNetUser AspNetUser { get; set; } ...... } public partial class AspNetUser { public string Id { get; set; } public string UserName { get; set; } public virtual Driver Driver { get; set; } ...... } and the following mapping: this.HasOptional(c => c.Driver) .WithOptionalPrincipal(a => a.AspNetUser) .Map(m => m

How to Define Foreign Key Relationships in Entity Framework other than the default method

时光总嘲笑我的痴心妄想 提交于 2019-12-11 06:19:54
问题 I have a problem I am trying to solve with the Entity Framework 6.0 and hope someone here can give some direction on. I am much more comfortable with ADO.NET but want to do this project in EF. I have an object called Policy and another called PayPlan public class Policy { //Various properties not relevant public PayPlan PaymentPlan { get; set; } } public class PayPlan { public int PayPlanId { get; set;} public string Description { get; set; } } As you can see, in this example, a PayPlan is a

Entity framework - Define connection where neither side is required

好久不见. 提交于 2019-12-11 06:06:19
问题 I have a problem, I have to create a model where we have two entities which CAN be linked together but can also exist as stand alone entities. The model currently looks like this: public class Authorisation { public int AuthorisationID { get; set; } public virtual Change Change { get; set; } } public class Change { public int ChangeID{ get; set; } public virtual Authorisation Authorisation { get; set; } public int? AuthorisationID{ get; set; } } The reason for this is that we can have an

Entity framework architecture for WPF MVVM applications

a 夏天 提交于 2019-12-11 05:54:56
问题 I'm currently developing an WPF application sticking to the MVVM-pattern. On the persistence side I'm using the Entity Framework (Code first) with repositories and UnitOfWork: The implementation is described here. I had a lot of good experiences with this architecture in web-context (asp.net MVC). Unfortunately using this architecture on desktop applications doesn't seem to be appropriate. I have some trouble: I'm loading my database model with the Unit Of Work- and Repository-pattern. It's