mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-19 06:40:57 +08:00
- 优化 多对多中间表主键配置错误的友好提醒;
This commit is contained in:
@@ -758,5 +758,13 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
|
||||
namespace FreeSql.Internal
|
||||
{
|
||||
@@ -1003,6 +1004,7 @@ namespace FreeSql.Internal
|
||||
var midTypePropsTrytb = tbmid.Properties.Where(a => a.Value.PropertyType == trytb.Type).FirstOrDefault().Value;
|
||||
//g.mysql.Select<Tag>().Where(a => g.mysql.Select<Song_tag>().Where(b => b.Tag_id == a.Id && b.Song_id == 1).Any());
|
||||
var lmbdWhere = isLazy ? new StringBuilder() : null;
|
||||
var minPkCols = new List<ColumnInfo>();
|
||||
|
||||
if (pnvAttr?.ManyToMany != null)
|
||||
{
|
||||
@@ -1039,6 +1041,8 @@ namespace FreeSql.Internal
|
||||
if (tbmid.Primarys.Any() == false)
|
||||
foreach (var c in trytbTf.Columns)
|
||||
tbmid.ColumnsByCs[c.CsName].Attribute.IsPrimary = true;
|
||||
else
|
||||
minPkCols.AddRange(trytbTf.Columns);
|
||||
|
||||
if (isLazy)
|
||||
{
|
||||
@@ -1086,6 +1090,8 @@ namespace FreeSql.Internal
|
||||
if (tbmid.Primarys.Any() == false)
|
||||
foreach (var c in tbrefTf.Columns)
|
||||
tbmid.ColumnsByCs[c.CsName].Attribute.IsPrimary = true;
|
||||
else
|
||||
minPkCols.AddRange(tbrefTf.Columns);
|
||||
|
||||
if (isLazy)
|
||||
{
|
||||
@@ -1129,6 +1135,8 @@ namespace FreeSql.Internal
|
||||
nvref.MiddleColumns.Add(trycol);
|
||||
if (tbmid.Primarys.Any() == false)
|
||||
trycol.Attribute.IsPrimary = true;
|
||||
else
|
||||
minPkCols.Add(trycol);
|
||||
|
||||
if (isLazy)
|
||||
{
|
||||
@@ -1169,6 +1177,8 @@ namespace FreeSql.Internal
|
||||
nvref.MiddleColumns.Add(trycol);
|
||||
if (tbmid.Primarys.Any() == false)
|
||||
trycol.Attribute.IsPrimary = true;
|
||||
else
|
||||
minPkCols.Add(trycol);
|
||||
|
||||
if (isLazy) lmbdWhere.Append(" && b.").Append(trycol.CsName).Append(" == a.").Append(tbref.Primarys[a].CsName);
|
||||
}
|
||||
@@ -1197,6 +1207,11 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(minPkCols.Any(c => tbmid.ColumnsByCs[c.CsName].Attribute.IsPrimary == false))
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 解析错误,中间类主键错误:{midType.Name}({string.Join(",", tbmid.Primarys.Select(a => a.CsName))}) 与两边不匹配");
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
}
|
||||
}
|
||||
|
||||
if (isLazy)
|
||||
|
||||
Reference in New Issue
Block a user