ef-core-2.2

Executing an SP in EF Core

余生颓废 提交于 2019-12-11 17:04:20
问题 I'm trying to execute an sp in ef core. ALTER PROCEDURE [dbo].[usp_get_counts_for_event_type_for_single_date] @OrgCode varchar(5), @ProcessDate date AS BEGIN SET NOCOUNT ON DECLARE @StartTime time = '00:00:00' DECLARE @EndTime time = '23:59:59' DECLARE @PeriodStart datetime = CONVERT(datetime, @ProcessDate) + CONVERT(datetime, @StartTime) DECLARE @PeriodEnd datetime = CONVERT(datetime, @ProcessDate) + CONVERT(datetime, @EndTime) -- Insert statements for procedure here SELECT CONVERT(VARCHAR

How can a JSON_VALUE be converted to a DateTime with EF Core 2.2?

不羁的心 提交于 2019-12-11 12:28:53
问题 I am mapping JSON_VALUE using the technique from How to write DbFunction's translation. Since not all values in the JSON are strings, conversion is sometimes necessary. When converting to int , everything is fine: var results = context.Set<SampleTable>() .Where(t1 => Convert.ToInt32( JsonExtensions.JsonValue(t1.SampleJson, "$.samplePath.sampleInt")) > 1); .ToList(); The resulting SQL is: SELECT * FROM [SampleTable] AS [t1] WHERE (CONVERT(int, JSON_VALUE([t1].[SampleJson], N'$.samplePath

.NET Core 3.0 ConsoleLoggerFactory for SQLite

本小妞迷上赌 提交于 2019-12-11 07:46:17
问题 using latest .Net Core (3.0 preview) and EF Core (3.0 preview) looking at a few online sources I did this: Program.cs public class MainWorker : IHostedService { public static readonly ILoggerFactory ConsoleLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole(); MyDbContext.cs protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connectionString = ... optionsBuilder .UseLoggerFactory(MainWorker.ConsoleLoggerFactory) .EnableSensitiveDataLogging

Entity Framework Multiple Connections Error

我怕爱的太早我们不能终老 提交于 2019-12-08 12:54:57
问题 I have a scenario wherein I have multiple connection strings defined under appsettings.json like this: "ConnectionString": { "ConnectionZone1": "Server=(localdb)\\mssqllocaldb;Database=Blogging;Trusted_Connection=True;", "ConnectionZone2": "Server=localhost;Database=Blogging;Trusted_Connection=True;" }, This I have registered in my startup.cs file as well: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<DbContextZone1>(options => options.UseSqlServer

Eager loading include with using UseLazyLoadingProxies

别来无恙 提交于 2019-12-07 20:16:32
问题 I am creating the db connection like so: protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder) { optionbuilder.UseLazyLoadingProxies().UseSqlite(@"Data Source=Data.db"); } And I am trying to access an object like so: public static User GetProfile(int uid) { using (Db db = new Db()) { return db.Users.Include(x => x.Settings).FirstOrDefault(x => x.UserId == uid); } } The user object is as follows: public class User { [Key] [DatabaseGenerated(DatabaseGeneratedOption

How does EF Core Modified Entity State behave?

笑着哭i 提交于 2019-12-07 06:28:43
问题 Does it matter we put the entity state = modified after changes or before making changes? using (var db = new LakshyaContext()) { foreach (var category in db.Categories) { db.Entry(category).State = EntityState.Modified; // before category.Count = 25; //Making Changes db.Entry(category).State = EntityState.Modified; //After } db.SaveChanges(); } 回答1: So first, let's get the most important thing out of the way: You are right. In your example, you don't need to manually call db.Entry(category)

Eager loading include with using UseLazyLoadingProxies

寵の児 提交于 2019-12-06 07:20:13
I am creating the db connection like so: protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder) { optionbuilder.UseLazyLoadingProxies().UseSqlite(@"Data Source=Data.db"); } And I am trying to access an object like so: public static User GetProfile(int uid) { using (Db db = new Db()) { return db.Users.Include(x => x.Settings).FirstOrDefault(x => x.UserId == uid); } } The user object is as follows: public class User { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string Name { get; set; } public DateTime? LastUsed{ get;

How does EF Core Modified Entity State behave?

青春壹個敷衍的年華 提交于 2019-12-05 10:36:03
Does it matter we put the entity state = modified after changes or before making changes? using (var db = new LakshyaContext()) { foreach (var category in db.Categories) { db.Entry(category).State = EntityState.Modified; // before category.Count = 25; //Making Changes db.Entry(category).State = EntityState.Modified; //After } db.SaveChanges(); } So first, let's get the most important thing out of the way: You are right. In your example, you don't need to manually call db.Entry(category).State = EntityState.Modified . This is because you are loading the entries (categories) from the context

No 'Access-Control-Allow-Origin' header in asp core and angular7

时光怂恿深爱的人放手 提交于 2019-11-28 06:20:40
问题 i need to download image from backend Asp Core 2.2 and show it in Angular . i create a component for show image in angular : in Html Code : <img [src]="src$ | async" class="img-fluid img-thumbnail"> in Ts File : @Input() ImagePath: string; ImageBlob: any; public src$: Observable<SafeUrl>; private imageSrc$: BehaviorSubject<string>; constructor(private downloadService: DownloadService, private domSanitizer: DomSanitizer) { this.imageSrc$ = new BehaviorSubject(null); this.src$ = this.imageSrc$