xyrile
EF Core how to add two same object in 1 model
public int UserId { get; set; }
[ForeignKey("UserId")]
public AccountModel Account { get; set; } = new();
public int MarkAsPaidById { get; set; }
[ForeignKey("MarkAsPaidById")]
public AccountModel MarkAsPaidByAccount { get; set; } = new();
public int UserId { get; set; }
[ForeignKey("UserId")]
public AccountModel Account { get; set; } = new();
public int MarkAsPaidById { get; set; }
[ForeignKey("MarkAsPaidById")]
public AccountModel MarkAsPaidByAccount { get; set; } = new();
[Table("Accounts")]
[PrimaryKey("UserId")]
public class AccountModel
{
public int UserId { get; set; }
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
[Table("Accounts")]
[PrimaryKey("UserId")]
public class AccountModel
{
public int UserId { get; set; }
public string Username { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
4 replies
Why does using `await` EF core execute command twice
I am using Blazor server app and add EF Core
Dependency
Here is the code where query executes twice
public class UserAccountService(AppDBContext context) : ControllerBase, IUserAccountService
{
private readonly AppDBContext _context = context;
[HttpGet]
public async Task<IEnumerable<UserAccountModel>> GetAccounts()
{
return await _context.Accounts.ToListAsync();
}
}
public class UserAccountService(AppDBContext context) : ControllerBase, IUserAccountService
{
private readonly AppDBContext _context = context;
[HttpGet]
public async Task<IEnumerable<UserAccountModel>> GetAccounts()
{
return await _context.Accounts.ToListAsync();
}
}
builder.Services.AddScoped<IUserAccountService, UserAccountService>();
builder.Services.AddScoped<IUserAccountService, UserAccountService>();
protected override async Task OnInitializedAsync()
{
var response = await UserAccountService.GetAccounts();
if (response != null)
{
accounts = response.ToList();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(accounts, Newtonsoft.Json.Formatting.Indented));
}
else
{
}
}
protected override async Task OnInitializedAsync()
{
var response = await UserAccountService.GetAccounts();
if (response != null)
{
accounts = response.ToList();
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(accounts, Newtonsoft.Json.Formatting.Indented));
}
else
{
}
}
14 replies
.NET 8 error when using ASP.NET AspNetCore.Reporting.LocalReport
var result = localReport.Execute(AspNetCore.Reporting.RenderType.ExcelOpenXml, 1, param, "");
Error message
Inner Exception 1:
DefinitionInvalidException: The definition of the report 'C:\FGCI Projects\FGCI Report Server\fgcireportserver\fgcireportservercore\fgcireportservercore\bin\Debug\net8.0\Reports\AccountingManagementReportFormats\voucherroutereportexcel.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
Inner Exception 2:
ReportProcessingException: An unexpected error occurred in Report Processing.
Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
Inner Exception 3:
InvalidOperationException: Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
Inner Exception 1:
DefinitionInvalidException: The definition of the report 'C:\FGCI Projects\FGCI Report Server\fgcireportserver\fgcireportservercore\fgcireportservercore\bin\Debug\net8.0\Reports\AccountingManagementReportFormats\voucherroutereportexcel.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
Inner Exception 2:
ReportProcessingException: An unexpected error occurred in Report Processing.
Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
Inner Exception 3:
InvalidOperationException: Compiler executable file C:\WINDOWS\Microsoft.NET\Framework64\v8.0.1\vbc.exe cannot be found.
1 replies
❔ Binary tree pre order
How to make a loop out of this ?
Tree tree = new Tree();
tree.root = new Node(1);
tree.root.left = new Node(12);
tree.root.right = new Node(9);
tree.root.left.left = new Node(5);
tree.root.left.right = new Node(6);
Tree tree = new Tree();
tree.root = new Node(1);
tree.root.left = new Node(12);
tree.root.right = new Node(9);
tree.root.left.left = new Node(5);
tree.root.left.right = new Node(6);
4 replies
Iterator (Argument 1 cannot convert from 'Coding.Exercise.Nodechar[]' to 'char*' Compilation failed)
public class Node<T>
{
public T value;
public Node<T> left, right, parent;
public Node(T value)
{
this.value = value;
}
public Node(T value, Node<T> left, Node<T> right)
{
this.value = value;
this.left = left;
this.right = right;
left.parent = right.parent = this;
}
public IEnumerable<Node<T>> PreOrder
{
get
{
return new PreOrderIterator<T>(this);
}
}
}
public class PreOrderIterator<T> : IEnumerable<Node<T>>
{
private Stack<Node<T>> stack = new Stack<Node<T>>();
public PreOrderIterator(Node<T> root)
{
stack.Push(root);
}
public IEnumerator<Node<T>> GetEnumerator()
{
foreach (Node<T> node in stack)
{
yield return node;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
public class Node<T>
{
public T value;
public Node<T> left, right, parent;
public Node(T value)
{
this.value = value;
}
public Node(T value, Node<T> left, Node<T> right)
{
this.value = value;
this.left = left;
this.right = right;
left.parent = right.parent = this;
}
public IEnumerable<Node<T>> PreOrder
{
get
{
return new PreOrderIterator<T>(this);
}
}
}
public class PreOrderIterator<T> : IEnumerable<Node<T>>
{
private Stack<Node<T>> stack = new Stack<Node<T>>();
public PreOrderIterator(Node<T> root)
{
stack.Push(root);
}
public IEnumerator<Node<T>> GetEnumerator()
{
foreach (Node<T> node in stack)
{
yield return node;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
12 replies
❔ Design pattern Iterator
So I was working with
Node<T>
in PreOrder Traversal when i try to test it gives me an error message saying Something is wrong in our systems, your code took too long to execute.
Here's my code
public class Node<T>
{
public T value;
public Node<T> left, right, parent;
public Node(T value)
{
this.value = value;
}
public Node(T value, Node<T> left, Node<T> right)
{
this.value = value;
this.left = left;
this.right = right;
left.parent = right.parent = this;
}
public IEnumerable<T> PreOrder
{
get
{
return new PreOrderIterator<T>(this);
}
}
}
public class PreOrderIterator<T> : IEnumerable<T>
{
private Stack<Node<T>> stack = new Stack<Node<T>>();
public PreOrderIterator(Node<T> root)
{
stack.Push(root);
}
public IEnumerator<T> GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
public class Node<T>
{
public T value;
public Node<T> left, right, parent;
public Node(T value)
{
this.value = value;
}
public Node(T value, Node<T> left, Node<T> right)
{
this.value = value;
this.left = left;
this.right = right;
left.parent = right.parent = this;
}
public IEnumerable<T> PreOrder
{
get
{
return new PreOrderIterator<T>(this);
}
}
}
public class PreOrderIterator<T> : IEnumerable<T>
{
private Stack<Node<T>> stack = new Stack<Node<T>>();
public PreOrderIterator(Node<T> root)
{
stack.Push(root);
}
public IEnumerator<T> GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
6 replies
Design pattern
So i was stuck in composite coding with c# I just cant get the ouput maybe someone know about this
namespace Coding.Exercise
{
public interface IValueContainer
{
}
public class SingleValue : IValueContainer
{
public int Value;
}
public class ManyValues : List<int>, IValueContainer
{
}
public static class ExtensionMethods
{
public static int Sum(this List<IValueContainer> containers)
{
int result = 0;
foreach (var c in containers)
foreach (var i in c)
result += i;
return result;
}
}
}
namespace Coding.Exercise
{
public interface IValueContainer
{
}
public class SingleValue : IValueContainer
{
public int Value;
}
public class ManyValues : List<int>, IValueContainer
{
}
public static class ExtensionMethods
{
public static int Sum(this List<IValueContainer> containers)
{
int result = 0;
foreach (var c in containers)
foreach (var i in c)
result += i;
return result;
}
}
}
1 replies