Subclass of collection property map & retrive datas #273
Closed
MehdiKacim
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
@MehdiKacim Hi, I converted issue to discussion. Previous discussion here: #124. Implementation isn't simple. If you have time you can implement feature and raise a PR. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hello @phnx47 ! First part : Query Generation The method did not support generic type parsing on a list. We are careful not to add the same properties so as not to have a key exception -- MSSQL ! Unit test : [Fact]
public static void SelectByIdJoinNested()
{
var generator = new SqlGenerator<ProviderOrder>(_sqlConnector, true);
var sqlQuery = generator.GetSelectById(1, null, q => q.ProviderOrderLines, q => q.ProviderOrderLines.First().ProviderOrderStatus);
Assert.Equal("SELECT [S_Cfo].[CommandeFournisseur_CoFo].[CoFo_ID], [CFLI].[CfLi_ID], [CFLI].[CoFo_ID], [CFLS].[CfLs_ID], [CFLS].[CfLi_ID] FROM [S_Cfo].[CommandeFournisseur_CoFo] INNER JOIN [S_Cfo.CommandeFournisseurLignes_CfLi] AS [CFLI] ON [CommandeFournisseur_CoFo].[CoFo_ID] = [CFLI].[CoFo_ID] INNER JOIN [S_Cfo.CommandeFournisseurLignesStatut_CfLs] AS [CFLS] ON [CommandeFournisseurLignes_CfLi].[CfLi_ID] = [CFLS].[CfLi_ID] WHERE [S_Cfo].[CommandeFournisseur_CoFo].[CoFo_ID] = @CoFo_ID", sqlQuery.GetSql());
} public static List<PropertyInfo> FindClassProperties<TEntity>(this Type objectType, List<PropertyInfo> allProperties)
{
if (_reflectionPropertyCache.TryGetValue(objectType, out var cachedEntry))
{
allProperties.AddRange(cachedEntry.Where(c => !allProperties.Any(a => a.Name == c.Name)));
return allProperties;
}
allProperties.AddRange(objectType.GetProperties()
.OrderByDescending(x => x.GetCustomAttribute<IdentityAttribute>() != null)
.ThenByDescending(x => x.GetCustomAttribute<KeyAttribute>() != null)
.ThenBy(p => p.GetCustomAttributes<ColumnAttribute>()
.Select(a => a.Order)
.DefaultIfEmpty(int.MaxValue)
.FirstOrDefault()).Where(o => !allProperties.Any(a => a.Name == o.Name)));
_reflectionPropertyCache.TryAdd(objectType, allProperties.ToArray());
foreach (var pi in allProperties)
{
var type = pi.PropertyType;
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
{
type = type.GetGenericArguments()[0];
return type.FindClassProperties<TEntity>(allProperties);
}
}
return allProperties;
} Mapping test : [Table(name: "CommandeFournisseur_CoFo", Schema = "S_Cfo")]
public class ProviderOrder
{
[Key, Identity]
public int CoFo_ID { get; set; }
[InnerJoin("S_Cfo.CommandeFournisseurLignes_CfLi", "CoFo_ID", "CoFo_ID", TableAlias = "CFLI")]
public List<ProviderOrderLine> ProviderOrderLines { get; set; }
}
[Table(name: "CommandeFournisseurLignes_CfLi", Schema = "S_Cfo")]
public class ProviderOrderLine
{
[Key, Identity]
public int CfLi_ID { get; set; }
public int CoFo_ID { get; set; }
[InnerJoin("S_Cfo.CommandeFournisseurLignesStatut_CfLs", "CfLi_ID", "CfLi_ID", TableAlias = "CFLS")]
public ProviderOrderStatus ProviderOrderStatus { get; set; }
}
[Table(name: "CommandeFournisseurLignesStatut_CfLs", Schema = "S_Cfo")]
public class ProviderOrderStatus
{
[Key, Identity]
public int CfLs_ID { get; set; }
public int CfLi_ID { get; set; }
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi !
I can retrieve the 'ProviderOrderLines' collection, but I can't retrieve the 'ProviderOrderStatus' files.
Is this feature possible? Because by Expression selector it doesn't work
Thanks in advance
Code
Beta Was this translation helpful? Give feedback.
All reactions