{%if (table.Type == DbTableType.StoreProcedure) {
	print("return;");
	return rTn;
 }
 %}using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using FreeSql.DataAnnotations;
{%
var dbf = dbfirst as FreeSql.IDbFirst;
var cols = (table.Columns as List<DbColumnInfo>);
var pks = (table.Primarys as List<DbColumnInfo>);
var fks = (table.Foreigns as List<DbForeignInfo>);

Func<string, string> UString = stra => stra.Substring(0, 1).ToUpper() + stra.Substring(1);
Func<DbColumnInfo, string> GetCsType = cola3 => {
	return dbf.GetCsType(cola3);
};
Func<DbForeignInfo, string> GetFkObjectName = fkx => {
	var eqfks = fks.Where(fk22a => fk22a.ReferencedTable.Name == fkx.ReferencedTable.Name);
	if (eqfks.Count() == 1) return "Obj_" + fkx.ReferencedTable.Name;
	var fkretname = fkx.Columns[0].Name;
	if (fkretname.EndsWith(fkx.ReferencedColumns[0].Name, StringComparison.CurrentCultureIgnoreCase)) fkretname = fkretname.Substring(0, fkretname.Length - fkx.ReferencedColumns[0].Name.Length).TrimEnd('_');
	if (fkretname.EndsWith(fkx.ReferencedTable.Name, StringComparison.CurrentCultureIgnoreCase)) fkretname = fkretname.Substring(0, fkretname.Length - fkx.ReferencedTable.Name.Length).TrimEnd('_');
	if (fkretname.StartsWith(fkx.ReferencedTable.Name, StringComparison.CurrentCultureIgnoreCase)) fkretname = fkretname.Substring(fkx.ReferencedTable.Name.Length).TrimStart('_');
	return "Obj_" + fkx.ReferencedTable.Name + (string.IsNullOrEmpty(fkretname) ? "" : ("_" + fkretname));
};
%}
namespace test.Model {

	[JsonObject(MemberSerialization.OptIn), Table(Name = "{#!string.IsNullOrEmpty(table.Schema) ? table.Schema + "." : ""}{#table.Name}"{if cols.Where(cola003 => cola003.Name.ToLower() == "is_deleted" || cola003.Name.ToLower() == "isdeleted").Any()}, SelectFilter = "a.IsDeleted = 1"{/if})]
	public partial class {#UString(table.Name)} {{for col,index in table.Columns}{%
			var findfks = fks.Where(fkaa => fkaa.Columns.Where(fkaac1 => fkaac1.Name == col.Name).Any());
		%}{if findfks.Any() == false}
		{if string.IsNullOrEmpty(col.Coment) == false}/// <summary>
		/// {#col.Coment.Replace("\r\n", "\n").Replace("\n", "\r\n		/// ")}
		/// </summary>{/if}
		[JsonProperty, Column(Name = "{#col.Name}", DbType = "{#col.DbTypeTextFull}"{if col.IsPrimary == true}, IsPrimary = true{/if}{if col.IsIdentity == true}, IsIdentity = true{/if}{if col.IsNullable == true}, IsNullable = true{/if})]
		public {#GetCsType(col)} {#UString(col.Name)} { get; set; }
		{else}
		private {#GetCsType(col)} _{#UString(col.Name)};
		{if string.IsNullOrEmpty(col.Coment) == false}/// <summary>
		/// {#col.Coment.Replace("\r\n", "\n").Replace("\n", "\r\n		/// ")}
		/// </summary>{/if}
		[JsonProperty, Column(Name = "{#col.Name}", DbType = "{#col.DbTypeTextFull}"{if col.IsPrimary == true}, IsPrimary = true{/if}{if col.IsIdentity == true}, IsIdentity = true{/if}{if col.IsNullable == true}, IsNullable = true{/if})]
		public {#GetCsType(col)} {#UString(col.Name)} { get => _{#UString(col.Name)}; set {
			if (_{#UString(col.Name)} == value) return;
			_{#UString(col.Name)} = value;{for fkcok2 in findfks}
			{#GetFkObjectName(fkcok2)} = null;{/for}
		} }
		{/if}{/for}{for fk in fks}
		public {#UString(fk.ReferencedTable.Name)} {#GetFkObjectName(fk)} { get; set; }
		{/for}
	}
}