WibblyWobbly
WibblyWobbly
CC#
Created by WibblyWobbly on 5/26/2023 in #help
❔ Expression<Func> using Reflection
Hello, I'm using LINQ to SQL as part of an old legacy Business Object Layer and trying to use the following code using reflection instead of hardcoding the types. Currently I have:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<WorkRequest>(m => m.WorkRequestItems);
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<WorkRequest>();
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<WorkRequest>(m => m.WorkRequestItems);
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<WorkRequest>();
This loads WorkRequestItems with WorkRequest upon execution. However, the desired outcome is to turn WorkRequest into T So something like:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<T>( //targetChildObject );
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<T>();
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<T>( //targetChildObject );
dc.LoadOptions = loadOptions;
Table table = dc.GetTable<T>();
T gets passed in from the controller. loadOptions.LoadWith<T> expects Expression<Func<T, object>> expression as it's argument. Any help would be appreciated.
7 replies
CC#
Created by WibblyWobbly on 4/26/2023 in #help
❔ Need help with strategy migrating legacy WebForms app to .Net Core
Hey all. I've been tasked with trying to come up with a strategy to migrate our legacy webforms .NET Framework application to .NET (Core) and Blazor. However, I have every little knowledge of .NET Framework and never migrated a application from 1 framework to another. This application is somewhat large with 13 class libraries and a Website. The website uses LINQ-to-SQL and various Business Objects to access data and CSLA version 3.8 for authentication and authorization. Users log in by means of username and password no link to an AD, access tokens nothing like that. It would take years to rebuild from the ground up so we're looking at a step by step approach where we can slowly incorporate newer features in .net core and migrate older code over. Can anyone point me in the right direction where I might find some useful documentation on the above or have any similar experiences.
3 replies
CC#
Created by WibblyWobbly on 12/1/2022 in #help
❔ Migration from .NET Framework 4.8 to .NET7, Need .NET Standard?
We have a project that is using LINQ-To-SQL and .NET Framework 4.8. The DAL is a separate Class Library project to the UI. We have been tasked with getting this DAL into a .NET 7 API to use with a desktop app that is being rewritten in .NET 7 (Possibly Blazor or React). So the 2 systems will talk to the same API however 1 DAL will be EFCore .NET 7 and 1 will be LINQ-TO-SQL (for now, until we re-write this in EFCore too). I thought the approach might be .NET Core API > .NET Standard 2.0 > .NET Framework 4.8 However when trying to access the .NET Framework 4.8 DataContext I get Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0 from my .NET Standard 2.0 Class Library .NET 7
[HttpGet]
public void GetDevices()
{
_deviceBridge.GetDevies();
}
[HttpGet]
public void GetDevices()
{
_deviceBridge.GetDevies();
}
.NET Standard 2.0
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
.NET Framework 4.8
public void GetDevies()
{
ProjectDataContext dc = this.Session.NewProjectDataContext();
}
public void GetDevies()
{
ProjectDataContext dc = this.Session.NewProjectDataContext();
}
When I reference System.Data.Linq (in .NET Standard or .NET 7) I get BadImageFormatException: Cannot load a reference assembly for execution. at runtime. I've also tried "Mindbox.Data.Linq" which is "A clone of Microsoft System.Data.Linq to allow multi-DLL extensibility and EF compatibility." Sadly still doesn't work. Am I approaching this all wrong? I've read .NET 7 might not even need .NET Standard however I'm getting a similar problem with System.Data.Linq when using just the .NET 7 > .NET Framework 4.8 in regards to System.Data.Linq.
23 replies
CC#
Created by WibblyWobbly on 10/28/2022 in #help
MediatR and CQRS for basic logic
So started doing abit of MediatR CQRS pattern in abit of Clean Architecture. I've been doing the Query and Commands for Database / API stuff as the articles suggest but what about general business logic? Say I have a List of People and I want to capitalize all their Surnames right so Wibbly Wobbly becomes Wibbly WOBBLY and find people aged 30 and above. Would it be:
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname()
{
IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery());
return await _mediator.Send(new ToCapitalSurnameAndOver30(people));
}

public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname()
{
IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery());
return await _mediator.Send(new ToCapitalSurnameAndOver30(people));
}

ToCapitalSurnameAndOver30 simply takes a list foreach person in people, gets the surname ToUpperCase() and if (person.Age > 30) add to another list maybe. Nothing fancy but using _mediator.Send() to get to this logic or:
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname()
{
IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery());
return await _myService.ToCapitalSurnameAndOver30(people)
}

public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname()
{
IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery());
return await _myService.ToCapitalSurnameAndOver30(people)
}

As you might find with most stuff. In other words, should you use it for the majority of logic or just API/Database stuff.
5 replies