This commit is contained in:
sunkaixuan 2018-10-13 11:03:25 +08:00
parent 6b9b23809c
commit a495651828
3 changed files with 27 additions and 3 deletions

View File

@ -537,6 +537,9 @@ namespace OrmTest.Demo
var s9 = db.Queryable<Student>().Select(it=>new Student() { Id=it.Id, TestId=1, Name=it.Name, CreateTime=it.CreateTime }).First();
var s10 = db.Queryable<Student>().Select(it => new Student() { Id = it.Id}).First();
//auto fill
var s11 = db.Queryable<Student, School>((st,sc)=>st.SchoolId==sc.Id).Select<ViewModelStudent3>().ToList();
}
private static void Sqlable()
{

View File

@ -18,5 +18,7 @@ namespace OrmTest.Models
public class ViewModelStudent3: Student
{
public string SchoolName { get; set; }
public string School_Name { get; set; }
public string ScId { get; set; }
}
}

View File

@ -36,8 +36,13 @@ namespace SqlSugar
new { asName = (expPars.type.Name + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList();
var joinModelDbColumns_WithType = columns.Select(it =>
new { asName = (expPars.type.Name +"_"+ it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList();
var joinModelProperties_WithTye = columns.Select(it =>
var joinModelProperties_WithType = columns.Select(it =>
new { asName = (expPars.type.Name +"_"+ _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList();
var joinModelDbColumnsWithSN = columns.Select(it =>
new { asName = (expPars.shortName + it.PropertyName), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList();
var joinModelPropertiesWithSN = columns.Select(it =>
new { asName = (expPars.shortName + _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type)), dbName = _context.EntityMaintenance.GetDbColumnName(it.PropertyName, expPars.type) }).ToList();
if (joinModelDbColumns.Any(it => it.asName.Equals(viewColumn.PropertyName,StringComparison.CurrentCultureIgnoreCase)))
{
var value = joinModelDbColumns.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase));
@ -74,9 +79,23 @@ namespace SqlSugar
selectItems.Add(new KeyValuePair<string, object>(expPars.shortName, value));
break;
}
if (joinModelProperties_WithTye.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)))
if (joinModelProperties_WithType.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)))
{
var value = joinModelProperties_WithTye.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase));
var value = joinModelProperties_WithType.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase));
if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase))
selectItems.Add(new KeyValuePair<string, object>(expPars.shortName, value));
break;
}
if (joinModelDbColumnsWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)))
{
var value = joinModelDbColumnsWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase));
if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase))
selectItems.Add(new KeyValuePair<string, object>(expPars.shortName, value));
break;
}
if (joinModelPropertiesWithSN.Any(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase)))
{
var value = joinModelPropertiesWithSN.First(it => it.asName.Equals(viewColumn.PropertyName, StringComparison.CurrentCultureIgnoreCase));
if (viewColumn.PropertyName.Equals(value.asName, StringComparison.CurrentCultureIgnoreCase))
selectItems.Add(new KeyValuePair<string, object>(expPars.shortName, value));
break;