Haqz
Haqz
CC#
Created by Haqz on 9/6/2023 in #help
❔ Attaching record from one of multiple tables to another's entity property.
So I should just scrap the idea of having some sort of funky magic to connect these two tables, and just merge their info? Based on the relationship of course
22 replies
CC#
Created by Haqz on 9/6/2023 in #help
❔ Attaching record from one of multiple tables to another's entity property.
So after some time I'm coming back to this issue, i put down the idea for the time when i implement at least one of the providers. So, what i came up with is to somehow make right join call on provider tables. This per se is not hard, but I'd like to somehow attach the data to one property on the main entity, preferably i'd like it to be eager loaded. When i was still pursuing this idea i thought about having some parent class, let's say Provider and inherit it for each of the provider types. Then after that in main entity i would just have the parent class as the type for the field, but when i done that it yelled with error Attempt to acess missing function For context the code i still somewhat remember:
//the main entity
class PaymentData
{
private readonly DataContext _context;
public PaymentData(DataContext context) => _context = context;
//some basic fields
[NonMapped]
public PaymentProvider? Provider
{
get
{
return _context.StandardProvider.FirstOrDefault(x => x.PaymentId == this.Id);
}
}
}
//the main entity
class PaymentData
{
private readonly DataContext _context;
public PaymentData(DataContext context) => _context = context;
//some basic fields
[NonMapped]
public PaymentProvider? Provider
{
get
{
return _context.StandardProvider.FirstOrDefault(x => x.PaymentId == this.Id);
}
}
}
Same error was given when i changed the Provider field to type object or dynamic. Is such stuff even possible? I'm coming from Node.js enviroment so i might even have the wrong idea of how to do it. Thanks in advance again!
22 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Well that settles my questions, for now, thanks once again for quick help!
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
HmmNoted
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Oh thaqt was just me looking for any option that would fetch, i will switch to Fluent API asap
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
So instead of calling the context dfirectly i should use the service for example creation of entities?
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var dbOption = new DbContextOptionsBuilder<DataContext>()
.UseSqlite($"Data Source={Path.Join(path, "WebMinRouteGroup_tests.db")}");
context = new DataContext(dbOption.Options);
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var dbOption = new DbContextOptionsBuilder<DataContext>()
.UseSqlite($"Data Source={Path.Join(path, "WebMinRouteGroup_tests.db")}");
context = new DataContext(dbOption.Options);
this sits in constructor of test, is there maybe better way to do it so i can access it in each and every test i create?
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Oh on the topic of tests, i was wondering, if what i did to get the context in tests is the right way?
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Well nonetheless problem is gone for now, thanks once again!
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Running it through visual studio so no idea either
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
I hate when stuff suddenly starts working because i dont know what was broken notLikeCat
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
I think so? Well if running single test doesnt recompile the code then i guess i wouldnt have the updated code
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Huh, it suddenly started working?
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Yes, i especially changed the sqlite file name to something else and ran only this test, and it was created in it
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Oke, give me a minute for that
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
Oh sorry forgot to include that: Right now:
System.ArgumentNullException: Value cannot be null. (Parameter 'entity')
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Remove(TEntity entity)
at service__payments.Repositories.PaymentDataRepository.Delete(String hash)
System.ArgumentNullException: Value cannot be null. (Parameter 'entity')
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Remove(TEntity entity)
at service__payments.Repositories.PaymentDataRepository.Delete(String hash)
But in some iteration of my tries it also said Sequence is empty or something like that
39 replies
CC#
Created by Haqz on 9/7/2023 in #help
✅ xUnit | Saved entity not found.
[Fact]
public async void DeletePayment_Passes_WithCorrectData()
{
//Arrange
var payment = context.PaymentDatas.Add(new PaymentData
{
Hash = "dupa",
RelatedHash= Guid.NewGuid().ToString(),
Sum = 1000,
MappedStatus= 0,
});
context.SaveChanges();
var definition = new { Message = "" };
//Act
var response = await _client.DeleteAsync("/payment/"+payment.Entity.Hash);
var test = context.PaymentDatas.Single(x => x.Hash == payment.Entity.Hash);
var entityEntry = context.Entry(test);
output.WriteLine(entityEntry.State.ToString());
output.WriteLine(await response.Content.ReadAsStringAsync());
var responsePaymentData = JsonConvert.DeserializeAnonymousType(await response.Content.ReadAsStringAsync(), definition);
output.WriteLine(response.ToString());
//Assert
//Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
//Assert.NotEmpty(responsePaymentData.Message);

}
[Fact]
public async void DeletePayment_Passes_WithCorrectData()
{
//Arrange
var payment = context.PaymentDatas.Add(new PaymentData
{
Hash = "dupa",
RelatedHash= Guid.NewGuid().ToString(),
Sum = 1000,
MappedStatus= 0,
});
context.SaveChanges();
var definition = new { Message = "" };
//Act
var response = await _client.DeleteAsync("/payment/"+payment.Entity.Hash);
var test = context.PaymentDatas.Single(x => x.Hash == payment.Entity.Hash);
var entityEntry = context.Entry(test);
output.WriteLine(entityEntry.State.ToString());
output.WriteLine(await response.Content.ReadAsStringAsync());
var responsePaymentData = JsonConvert.DeserializeAnonymousType(await response.Content.ReadAsStringAsync(), definition);
output.WriteLine(response.ToString());
//Assert
//Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
//Assert.NotEmpty(responsePaymentData.Message);

}
39 replies
CC#
Created by Haqz on 9/6/2023 in #help
❔ Attaching record from one of multiple tables to another's entity property.
So basically i should create parent class Provider and inherit from it for specific providers?
22 replies
CC#
Created by Haqz on 9/6/2023 in #help
❔ Attaching record from one of multiple tables to another's entity property.
Thus why I'm in need of some sort of virtual/computed column
22 replies
CC#
Created by Haqz on 9/6/2023 in #help
❔ Attaching record from one of multiple tables to another's entity property.
The thing is that I'll have multiple providers and they will hold different data, so let's say in the public Provider CurrentProvider { get; set; } I'll hold either of PayPal, Stripe, PayU data
22 replies