ef-core-2.0

How do I finalize a class based Saga, so that it is deleted from the SQL database (EF Core)?

烂漫一生 提交于 2019-12-01 11:41:42
问题 I am trying to learn more about Mass Transit as we are thinking about adopting it. I now have the class based Saga below, which works as expected: public class EchoSaga : ISaga, InitiatedBy<TextEntered>, Orchestrates<TextEchoStart>, Orchestrates<EchoEnd> { public Guid CorrelationId { get; set; } public string CurrentState { get; set; } public string Text { get; set; } public Task Consume(ConsumeContext<TextEntered> context) { CurrentState = "Entered"; Text = context.Message.Text; return Task

EFCore nullable relationship setting onDelete: ReferentialAction.Restrict

时光怂恿深爱的人放手 提交于 2019-12-01 02:54:46
I'm running efcore 2.0.1. I have a model: public class BigAwesomeDinosaurWithTeeth { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public ICollection<YummyPunyPrey> YummyPunyPrey { get; set; } } public class YummyPunyPrey { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } public Guid? BigAwesomeDinosaurWithTeethId { get; set; } [ForeignKey("BigAwesomeDinosaurWithTeethId")] public BigAwesomeDinosaurWithTeeth BigAwesomeDinosaurWithTeeth { get; set; } } I have no fluent api on these two classes. But when I generate

Asp.net core 2.1 crashing due to model InverseProperty

百般思念 提交于 2019-12-01 02:37:52
问题 My site is crashing on load with an extremely long unhandled exception in System.Reflection on the first call to the DbContext. Using ef-core 2.1 rc1 System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Reflection.IntrospectionExtensions.GetTypeInfo(Type type) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.InversePropertyAttributeConvention.ConfigureInverseNavigation(InternalEntityTypeBuilder entityTypeBuilder, MemberInfo navigationMemberInfo,

EF Core 2.0 Enums stored as string

落花浮王杯 提交于 2019-11-30 19:07:42
I was able to store an enum as a string in the database. builder.Entity<Company>(eb => { eb.Property(b => b.Stage).HasColumnType("varchar(20)"); }); But when it comes time to query EF doesn't know to parse the string into an enum. How can I query like so: context .Company .Where(x => x.Stage == stage) This is the exception: Conversion failed when converting the varchar value 'Opportunity' to data type int Value Conversions feature is new in EF Core 2.1. Value converters allow property values to be converted when reading from or writing to the database. This conversion can be from one value to

EF Core 2.0 Enums stored as string

ⅰ亾dé卋堺 提交于 2019-11-30 03:16:53
问题 I was able to store an enum as a string in the database. builder.Entity<Company>(eb => { eb.Property(b => b.Stage).HasColumnType("varchar(20)"); }); But when it comes time to query EF doesn't know to parse the string into an enum. How can I query like so: context .Company .Where(x => x.Stage == stage) This is the exception: Conversion failed when converting the varchar value 'Opportunity' to data type int 回答1: Value Conversions feature is new in EF Core 2.1. Value converters allow property

GetEntityTypes: configure entity properties using the generic version of .Property<TEntity> in EF Core

大憨熊 提交于 2019-11-29 08:13:24
In my EF core project I have a few entities that inherit from a base class DBEntity: public abstract class DBEntity { public int Id { get; set; } public DateTime CreatedOn { get; set; } public DateTime UpdatedOn { get; set; } public EntityStatus EntityStatus { get; set; } } I want to set some specific properties with default value for every entity that inherits from DBEntity. Currently I'm using this code: protected override void OnModelCreating(ModelBuilder modelBuilder) { var entities = modelBuilder.Model .GetEntityTypes() .Where(w => w.ClrType.IsSubclassOf(typeof(DBEntity))) .Select(p =>

EF Core 2.0 connection string in Azure Functions .NET Core

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:59:13
I'm using EF core 2.0 in Azure Functions using .net core. I'm trying to read db ConnectionString from local.settings.json, which is defined: { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "AzureWebJobsDashboard": "UseDevelopmentStorage=true" }, "ConnectionStrings": { "MyDbConnStr": "Data Source=.;Initial Catalog=xxxxxxx" } } Environment.GetEnvironmentVariable() doesn't return any connection string info neither I can use ConfigurationManager.ConnectionStrings with .net core. How do I access the connection string from the code? You could use one of the

GetEntityTypes: configure entity properties using the generic version of .Property<TEntity> in EF Core

落花浮王杯 提交于 2019-11-28 01:57:48
问题 In my EF core project I have a few entities that inherit from a base class DBEntity: public abstract class DBEntity { public int Id { get; set; } public DateTime CreatedOn { get; set; } public DateTime UpdatedOn { get; set; } public EntityStatus EntityStatus { get; set; } } I want to set some specific properties with default value for every entity that inherits from DBEntity. Currently I'm using this code: protected override void OnModelCreating(ModelBuilder modelBuilder) { var entities =

How can I stop EF Core from creating a filtered index on a nullable column

左心房为你撑大大i 提交于 2019-11-28 01:03:05
I have this model: public class Subject { public int Id { get; set; } [Required] [StringLength(50)] public string Name { get; set; } public int LevelId { get; set; } [ForeignKey("LevelId")] public Level Level { get; set; } [Column(TypeName = "datetime2")] public DateTime? DeletedAt { get; set; } } And index configured via Fluent API: entityBuilder.HasIndex(e => new { e.LevelId, e.Name, e.DeletedAt }) .IsUnique(); It's creating a table with a unique filtered index. How can I prevent EF from adding the filter? I just want the index and don't want it filtered. Creating filtered index excluding

EF Core 2.0 connection string in Azure Functions .NET Core

耗尽温柔 提交于 2019-11-28 00:17:44
问题 I'm using EF core 2.0 in Azure Functions using .net core. I'm trying to read db ConnectionString from local.settings.json, which is defined: { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "AzureWebJobsDashboard": "UseDevelopmentStorage=true" }, "ConnectionStrings": { "MyDbConnStr": "Data Source=.;Initial Catalog=xxxxxxx" } } Environment.GetEnvironmentVariable() doesn't return any connection string info neither I can use ConfigurationManager