mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	rename ArrayToMany to PgArrayToMany
This commit is contained in:
		@@ -157,7 +157,7 @@ namespace FreeSql
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                case TableRefType.OneToOne:
 | 
					                case TableRefType.OneToOne:
 | 
				
			||||||
                case TableRefType.ManyToOne:
 | 
					                case TableRefType.ManyToOne:
 | 
				
			||||||
                case TableRefType.ArrayToMany:
 | 
					                case TableRefType.PgArrayToMany:
 | 
				
			||||||
                    throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
 | 
					                    throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -227,7 +227,7 @@ namespace FreeSql
 | 
				
			|||||||
                        else await refSet.AddOrUpdateAsync(propValItem);
 | 
					                        else await refSet.AddOrUpdateAsync(propValItem);
 | 
				
			||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
                    case TableRefType.ManyToOne:
 | 
					                    case TableRefType.ManyToOne:
 | 
				
			||||||
                    case TableRefType.ArrayToMany:
 | 
					                    case TableRefType.PgArrayToMany:
 | 
				
			||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -168,7 +168,7 @@ namespace FreeSql
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                case TableRefType.OneToOne:
 | 
					                case TableRefType.OneToOne:
 | 
				
			||||||
                case TableRefType.ManyToOne:
 | 
					                case TableRefType.ManyToOne:
 | 
				
			||||||
                case TableRefType.ArrayToMany:
 | 
					                case TableRefType.PgArrayToMany:
 | 
				
			||||||
                    throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
 | 
					                    throw new ArgumentException(DbContextStrings.PropertyOfType_IsNot_OneToManyOrManyToMany(_table.Type.FullName, propertyName));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -238,7 +238,7 @@ namespace FreeSql
 | 
				
			|||||||
                        else refSet.AddOrUpdate(propValItem);
 | 
					                        else refSet.AddOrUpdate(propValItem);
 | 
				
			||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
                    case TableRefType.ManyToOne:
 | 
					                    case TableRefType.ManyToOne:
 | 
				
			||||||
                    case TableRefType.ArrayToMany:
 | 
					                    case TableRefType.PgArrayToMany:
 | 
				
			||||||
                        return;
 | 
					                        return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -154,7 +154,7 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                                {
 | 
					                                {
 | 
				
			||||||
                                    case TableRefType.ManyToMany:
 | 
					                                    case TableRefType.ManyToMany:
 | 
				
			||||||
                                    case TableRefType.OneToMany:
 | 
					                                    case TableRefType.OneToMany:
 | 
				
			||||||
                                    case TableRefType.ArrayToMany:
 | 
					                                    case TableRefType.PgArrayToMany:
 | 
				
			||||||
                                        continue;
 | 
					                                        continue;
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                                if (_tables.Any(a => a.Alias == $"{map.First().Table.Alias}__{memProp.Name}") == false) continue;
 | 
					                                if (_tables.Any(a => a.Alias == $"{map.First().Table.Alias}__{memProp.Name}") == false) continue;
 | 
				
			||||||
@@ -2195,7 +2195,13 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                        for (var tidx = 0; tidx < memberTbref.Columns.Count; tidx++)
 | 
					                        for (var tidx = 0; tidx < memberTbref.Columns.Count; tidx++)
 | 
				
			||||||
                            select.Where($"{select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[tidx].Attribute.Name)} = {omtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[tidx].Attribute.Name)}");
 | 
					                            select.Where($"{select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[tidx].Attribute.Name)} = {omtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[tidx].Attribute.Name)}");
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case TableRefType.ArrayToMany:
 | 
					                    case TableRefType.PgArrayToMany:
 | 
				
			||||||
 | 
					                        var amtReftbname = e.FreeParse(Expression.MakeMemberAccess(memberExp.Expression, exp3Tb.Properties[exp3Tb.ColumnsByPosition[0].CsName]));
 | 
				
			||||||
 | 
					                        amtReftbname = amtReftbname.Substring(0, amtReftbname.Length - commonExp._common.QuoteSqlName(exp3Tb.ColumnsByPosition[0].Attribute.Name).Length - 1);
 | 
				
			||||||
 | 
					                        if (memberTbref.RefColumns[0] == select._tables[0].Table.Primarys[0])
 | 
				
			||||||
 | 
					                            select.Where($"{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)} @> {select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)}");
 | 
				
			||||||
 | 
					                        else if (memberTbref.Columns[0] == select._tables[0].Table.Primarys[0])
 | 
				
			||||||
 | 
					                            select.Where($"{amtReftbname}.{commonExp._common.QuoteSqlName(memberTbref.RefColumns[0].Attribute.Name)} @> {select._tables[0].Alias}.{commonExp._common.QuoteSqlName(memberTbref.Columns[0].Attribute.Name)}");
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2244,7 +2250,9 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                            if (select != null) return;
 | 
					                            if (select != null) return;
 | 
				
			||||||
                            LocalInitSelectProvider();
 | 
					                            LocalInitSelectProvider();
 | 
				
			||||||
                            continue;
 | 
					                            continue;
 | 
				
			||||||
                        case TableRefType.ArrayToMany:
 | 
					                        case TableRefType.PgArrayToMany:
 | 
				
			||||||
 | 
					                            if (select != null) return;
 | 
				
			||||||
 | 
					                            LocalInitSelectProvider();
 | 
				
			||||||
                            continue;
 | 
					                            continue;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -418,6 +418,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                case TableRefType.ManyToMany:
 | 
					                case TableRefType.ManyToMany:
 | 
				
			||||||
                case TableRefType.OneToMany:
 | 
					                case TableRefType.OneToMany:
 | 
				
			||||||
 | 
					                case TableRefType.PgArrayToMany:
 | 
				
			||||||
                    var funcType = typeof(Func<,>).MakeGenericType(_tables[0].Table.Type, typeof(IEnumerable<>).MakeGenericType(parTbref.RefEntityType));
 | 
					                    var funcType = typeof(Func<,>).MakeGenericType(_tables[0].Table.Type, typeof(IEnumerable<>).MakeGenericType(parTbref.RefEntityType));
 | 
				
			||||||
                    var navigateSelector = Expression.Lambda(funcType, exp, _tables[0].Parameter);
 | 
					                    var navigateSelector = Expression.Lambda(funcType, exp, _tables[0].Parameter);
 | 
				
			||||||
                    var incMethod = this.GetType().GetMethod("IncludeMany");
 | 
					                    var incMethod = this.GetType().GetMethod("IncludeMany");
 | 
				
			||||||
@@ -430,8 +431,6 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                    var curTb = _commonUtils.GetTableByEntity(exp.Type);
 | 
					                    var curTb = _commonUtils.GetTableByEntity(exp.Type);
 | 
				
			||||||
                    _commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(exp, curTb.Properties[curTb.ColumnsByCs.First().Value.CsName]), null, null, null);
 | 
					                    _commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(exp, curTb.Properties[curTb.ColumnsByCs.First().Value.CsName]), null, null, null);
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case TableRefType.ArrayToMany:
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return this;
 | 
					            return this;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -1175,7 +1174,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                            dicList.Clear();
 | 
					                            dicList.Clear();
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case TableRefType.ArrayToMany:
 | 
					                    case TableRefType.PgArrayToMany:
 | 
				
			||||||
                        if (true)
 | 
					                        if (true)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            var subList = new List<TNavigate>();
 | 
					                            var subList = new List<TNavigate>();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -150,6 +150,6 @@ namespace FreeSql.Internal.Model
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    public enum TableRefType
 | 
					    public enum TableRefType
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        OneToOne, ManyToOne, OneToMany, ManyToMany, ArrayToMany
 | 
					        OneToOne, ManyToOne, OneToMany, ManyToMany, PgArrayToMany
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -4,6 +4,7 @@ using System;
 | 
				
			|||||||
using System.Collections;
 | 
					using System.Collections;
 | 
				
			||||||
using System.Collections.Concurrent;
 | 
					using System.Collections.Concurrent;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
using System.Data;
 | 
					using System.Data;
 | 
				
			||||||
using System.Data.Common;
 | 
					using System.Data.Common;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
@@ -623,6 +624,7 @@ namespace FreeSql.Internal
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            //List 或 ICollection,一对多、多对多
 | 
					            //List 或 ICollection,一对多、多对多
 | 
				
			||||||
            var propElementType = pnv.PropertyType.GetGenericArguments().FirstOrDefault() ?? pnv.PropertyType.GetElementType();
 | 
					            var propElementType = pnv.PropertyType.GetGenericArguments().FirstOrDefault() ?? pnv.PropertyType.GetElementType();
 | 
				
			||||||
 | 
					            var propTypeIsObservableCollection = propElementType != null && pnv.PropertyType == typeof(ObservableCollection<>).MakeGenericType(propElementType);
 | 
				
			||||||
            if (propElementType != null)
 | 
					            if (propElementType != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (typeof(IEnumerable).IsAssignableFrom(pnv.PropertyType) == false) return;
 | 
					                if (typeof(IEnumerable).IsAssignableFrom(pnv.PropertyType) == false) return;
 | 
				
			||||||
@@ -992,17 +994,18 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    var isArrayToMany = false;
 | 
					                    var isArrayToMany = false;
 | 
				
			||||||
                    var lmbdWhere = isLazy ? new StringBuilder() : null;
 | 
					                    var lmbdWhere = isLazy ? new StringBuilder() : null;
 | 
				
			||||||
 | 
					                    var cscodeExtLogic = "";
 | 
				
			||||||
                    //Pgsql Array[] To Many
 | 
					                    //Pgsql Array[] To Many
 | 
				
			||||||
                    if (common._orm.Ado.DataType == DataType.PostgreSQL)
 | 
					                    if (common._orm.Ado.DataType == DataType.PostgreSQL)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        //class User {
 | 
					                        //class User {
 | 
				
			||||||
                        //  public int[] RoleIds { get; set; }
 | 
					                        //  public int[] RoleIds { get; set; }
 | 
				
			||||||
                        //  [Navigate(nameof(RoleIds))]
 | 
					                        //  [Navigate(nameof(RoleIds))]
 | 
				
			||||||
                        //  public Role[] Roles { get; set; }
 | 
					                        //  public List<Role> Roles { get; set; }
 | 
				
			||||||
                        //}
 | 
					                        //}
 | 
				
			||||||
                        //class Role {
 | 
					                        //class Role {
 | 
				
			||||||
                        //  [Navigate(nameof(User.RoleIds))]
 | 
					                        //  [Navigate(nameof(User.RoleIds))]
 | 
				
			||||||
                        //  public User[] Users { get; set; }
 | 
					                        //  public List<User> Users { get; set; }
 | 
				
			||||||
                        //}
 | 
					                        //}
 | 
				
			||||||
                        ColumnInfo trycol = null;
 | 
					                        ColumnInfo trycol = null;
 | 
				
			||||||
                        if (tbref.Primarys.Length == 1)
 | 
					                        if (tbref.Primarys.Length == 1)
 | 
				
			||||||
@@ -1038,11 +1041,14 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                            isArrayToMany = trycol != null;
 | 
					                            isArrayToMany = trycol != null;
 | 
				
			||||||
                            if (isArrayToMany)
 | 
					                            if (isArrayToMany)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                lmbdWhere.Append("this.").Append(trycol.CsName).Append(".Contains(a.").Append(tbref.Primarys[0].CsName).Append(")");
 | 
					                                cscodeExtLogic = $"			if (this.{trycol.CsName} == null) return null;			\r\nif (this.{trycol.CsName}.Any() == false) return new {(propTypeIsObservableCollection ? "ObservableCollection" : "List")}<{propElementType.DisplayCsharp()}>();\r\n";
 | 
				
			||||||
 | 
					                                lmbdWhere.Append("this.").Append(trycol.CsName).Append(".Contains(a.").Append(tbref.Primarys[0].CsName);
 | 
				
			||||||
 | 
					                                if (trycol.CsType.GetElementType().IsNullableType() == false && tbref.Primarys[0].CsType.IsNullableType()) lmbdWhere.Append(".Value");
 | 
				
			||||||
 | 
					                                lmbdWhere.Append(")");
 | 
				
			||||||
                                nvref.Columns.Add(trycol);
 | 
					                                nvref.Columns.Add(trycol);
 | 
				
			||||||
                                nvref.RefColumns.Add(tbref.Primarys[0]);
 | 
					                                nvref.RefColumns.Add(tbref.Primarys[0]);
 | 
				
			||||||
                                nvref.RefEntityType = tbref.Type;
 | 
					                                nvref.RefEntityType = tbref.Type;
 | 
				
			||||||
                                nvref.RefType = TableRefType.ArrayToMany;
 | 
					                                nvref.RefType = TableRefType.PgArrayToMany;
 | 
				
			||||||
                                trytb.AddOrUpdateTableRef(pnv.Name, nvref);
 | 
					                                trytb.AddOrUpdateTableRef(pnv.Name, nvref);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@@ -1080,11 +1086,14 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                            isArrayToMany = trycol != null;
 | 
					                            isArrayToMany = trycol != null;
 | 
				
			||||||
                            if (isArrayToMany)
 | 
					                            if (isArrayToMany)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                lmbdWhere.Append("a.").Append(trycol.CsName).Append(".Contains(this.").Append(trytb.Primarys[0].CsName).Append(")");
 | 
					                                cscodeExtLogic = $"			if (this.{trytb.Primarys[0].CsName} == null) return null;\r\n";
 | 
				
			||||||
 | 
					                                lmbdWhere.Append("a.").Append(trycol.CsName).Append(".Contains(this.").Append(trytb.Primarys[0].CsName);
 | 
				
			||||||
 | 
					                                if (trycol.CsType.GetElementType().IsNullableType() == false && trytb.Primarys[0].CsType.IsNullableType()) lmbdWhere.Append(".Value");
 | 
				
			||||||
 | 
					                                lmbdWhere.Append(")");
 | 
				
			||||||
                                nvref.Columns.Add(tbref.Primarys[0]);
 | 
					                                nvref.Columns.Add(tbref.Primarys[0]);
 | 
				
			||||||
                                nvref.RefColumns.Add(trycol);
 | 
					                                nvref.RefColumns.Add(trycol);
 | 
				
			||||||
                                nvref.RefEntityType = tbref.Type;
 | 
					                                nvref.RefEntityType = tbref.Type;
 | 
				
			||||||
                                nvref.RefType = TableRefType.ArrayToMany;
 | 
					                                nvref.RefType = TableRefType.PgArrayToMany;
 | 
				
			||||||
                                trytb.AddOrUpdateTableRef(pnv.Name, nvref);
 | 
					                                trytb.AddOrUpdateTableRef(pnv.Name, nvref);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@@ -1205,6 +1214,7 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                        if (vp?.Item2 == true)
 | 
					                        if (vp?.Item2 == true)
 | 
				
			||||||
                        { //get 重写
 | 
					                        { //get 重写
 | 
				
			||||||
                            cscode.Append("		").Append(propGetModification).Append(" get {\r\n")
 | 
					                            cscode.Append("		").Append(propGetModification).Append(" get {\r\n")
 | 
				
			||||||
 | 
					                                .Append(cscodeExtLogic)
 | 
				
			||||||
                                .Append("			if (base.").Append(pnv.Name).Append(" == null && __lazy__").Append(pnv.Name).AppendLine(" == false) {");
 | 
					                                .Append("			if (base.").Append(pnv.Name).Append(" == null && __lazy__").Append(pnv.Name).AppendLine(" == false) {");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            if (nvref.Exception == null)
 | 
					                            if (nvref.Exception == null)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user