entity-framework

Does it make sense to use MetadataType to enforce validations in case of Code First?

跟風遠走 提交于 2020-07-05 01:28:31
问题 I seem to understand the reason behind taking help of MetadataTypeAttribute to Add Validation to the Model in case of Database First as we want to avoid the changes being overwritten when the model is generated from the database next time. I've noticed few people defining validation using MetadataType even when they're using Code First approach and there is no chance of their Entity Classes being overwritten by some kind of auto-generation of code. Does it make any sense to not apply these

Ignore properties in data model while keeping them in EF Core migrations

徘徊边缘 提交于 2020-07-04 20:50:24
问题 I am creating a greenfield application that uses EF Core which must talk to a legacy database. I want EF to ignore some of the columns in the database because they will eventually be deprecated and I don't want them in the new entity model. I can't remove them yet as the legacy system still relies on them. For an unwanted database column called DeprecatedFeature , I want to do something like: modelBuilder.Entity<MyEntity>(entity => { entity.HasKey(t => t.Id); entity.ToTable("MyEntity");

Does Entity Framework 6.1 support an XML data type natively?

我与影子孤独终老i 提交于 2020-07-04 10:08:54
问题 Some RDBMSs (including SQL Server) support XML columns. I'd prefer not mapping such a column to the string data type. Does Entity Framework 6.1 support XML natively in any way? More specifically, can I map an xml column to one of the XML data types of .NET (such as XElement or XmlElement )? Does Entity Framework support XQuery that is integrated into normal LINQ queries and is translated to SQL queries? 回答1: No, only mapping it to string and then having to stream it back in to an XML document

How to persist a list of strings with Entity Framework Core?

烂漫一生 提交于 2020-07-04 07:09:01
问题 Let us suppose that we have one class which looks like the following: public class Entity { public IList<string> SomeListOfValues { get; set; } // Other code } Now, suppose we want to persist this using EF Core Code First and that we are using a RDMBS like SQL Server. One possible approach is obviously to create a wraper class Wraper which wraps the string: public class Wraper { public int Id { get; set; } public string Value { get; set; } } And to refactor the class so that it now depends on

Entity Framework Core cascade delete one to many relationship

老子叫甜甜 提交于 2020-07-01 10:38:05
问题 public class Station : IEntitie { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDispatchStations { get; set; } public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDestinationStations { get; set; } } public class RegulatorySchedule : IEntitie { [Key] public int Id { get; set; } public virtual Station DispatchStation { get; set; } public virtual Station DestinationStation {

Entity Framework Core cascade delete one to many relationship

懵懂的女人 提交于 2020-07-01 10:37:48
问题 public class Station : IEntitie { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDispatchStations { get; set; } public virtual ICollection<RegulatorySchedule> RegulatoryScheduleDestinationStations { get; set; } } public class RegulatorySchedule : IEntitie { [Key] public int Id { get; set; } public virtual Station DispatchStation { get; set; } public virtual Station DestinationStation {

C# Entity Framework: Linq Filter on GrandChildren and Conduct a Select on the Parent with Attributes

烈酒焚心 提交于 2020-06-29 03:42:31
问题 Our company is currently using Entity Framework Net Core 2.2 with Sql Server Trying to find all Distinct customers who purchased a certain Product Input Parameter . The following EF Linq query was written to get the distinct Customers. Later another question came up, how do we get more (navigation) properties of customer? Should Include be placed Before the Where or After the Where? Does it matter? When running the SQL Profiler, it noted no difference in the queries. I just wanted to be sure

How do i use the AllowHtml attribute with the entity framework

China☆狼群 提交于 2020-06-29 02:21:34
问题 How would i go about adding the [AllowHtml] attribute to an entity framework generated class without the attribute being overwritten the next time the code is generated? I am looking to simply allow CKEditor to post information back to my MVC4 application using Razor without having to use [ValidateReuqest(false)] on my Content entity class. 回答1: You can use the [MetadataType] attribute to add metadata/attributes to your classes permanently without having to edit the original classes. For the

Why does response time go up when the number of concurrent requests per second to my Asp.Net Core API goes up

房东的猫 提交于 2020-06-28 09:22:14
问题 I'm testing an endpoint under load. For 1 request per second, the average response time is around 200ms. The endpoint does a few DB lookups (all read) that are pretty fast and it's async throughout. However when doing a few hundred requests per second (req/sec), the average response time goes up to over a second. I've had a look at the best practices guide at: https://docs.microsoft.com/en-us/aspnet/core/performance/performance-best-practices?view=aspnetcore-2.2 Some suggestions like " Avoid

Seed Roles (RoleManager vs RoleStore)

自古美人都是妖i 提交于 2020-06-28 06:46:08
问题 Through looking at the posts here, I've seen two different ways of creating ASP.NET Identity roles through Entity Framework seeding. One way uses RoleManager and the other uses RoleStore . I was wondering if there is a difference between the two. As using the latter will avoid one less initialization string[] roles = { "Admin", "Moderator", "User" }; // Create Role through RoleManager var roleStore = new RoleStore<IdentityRole>(context); var manager = new RoleManager<IdentityRole>(roleStore);