MicroLite icon indicating copy to clipboard operation
MicroLite copied to clipboard

How to map nested classes

Open frankiDotNet opened this issue 7 years ago • 6 comments

I could not find anything about mapping calsses that contains sub classes.

[Table("TableA")]
public class ClassA{

[COLUMN("B_ID")]
public BId {get; set;}

[COLUMN("b")]
public ClassB b{get; set;}
}

[Table("TableB")]
public class ClassB{

[COLUMN("ID")]
public Int32 Id{get; set;}
}

How to get this e.g. with a join or how do I load class A with nested B objects, that could have relations like one to one or one to many ?

frankiDotNet avatar Mar 14 '17 11:03 frankiDotNet

This isn't currently supported in MicroLite, it's something I'm considering for MicroLite 7.0 but for now you will need to do that additional fetch yourself (the upside is you can choose if & when that occurs) using the Include API

TrevorPilley avatar Mar 14 '17 11:03 TrevorPilley

Ok, sorry for the late response, had to recover from the shock ;-) I didn't think about it is not possible in this way. Ok if I use includes, is it possible to log all db sql queries that are made(nlog). So that I can see what is really happening at db level? I know this question is not helping but do you have release date for the version 7? And will there be a breaking change in this behaviour?

frankiDotNet avatar Mar 14 '17 20:03 frankiDotNet

All that happens is 2 or more individual queries are sent to the database server as a single request over a single connection and the results are returned in separate datasets which are then parsed into objects and made available to the caller.

As far as logging the traffic, queries aren't written to the log to avoid sensitive data being stored but you can use something like the profiler in MS SQL Server to see what requests are made.

TrevorPilley avatar Mar 14 '17 22:03 TrevorPilley

There's no firm time frame for 7.0 at the moment, I'm finishing the OData 4.0 work in the WebApi extension before I pick up on 7.0.

There may well be breaking changes in 7.0 but those will be detailed in the release notes and on the blog once known.

TrevorPilley avatar Mar 14 '17 22:03 TrevorPilley

Thanks for the reply and for the detailed information. I appreciate your project, and I try to avoid entity framework as long as I can, but need a good alternative. I think yours is getting more a really good one. Last thing before I close the issue (question). I asked about logging each sql query that is applied to the db, is this possible?

frankiDotNet avatar Mar 15 '17 05:03 frankiDotNet

Not in MicroLite itself, the standard way to do that is with the profiling tools that are part of the database server e.g. SQL Server Profiler

TrevorPilley avatar Mar 15 '17 06:03 TrevorPilley