JoinTableAttribute.JoinType Property
.NET Standard 2.x
Gets or sets the type of join operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public SqlJoinType JoinType { get; set; }
Property Value
The type of the join operator.
Examples
The following code example demonstrates how to use the JoinType
property of JoinTable
Attribute. It uses LEFT JOIN to join Course table with StudentGrade table.
Model: CourseJoinTableJoinType
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.Models.School
{
/// <summary>
/// This model class maps to the dbo.Course and dbo.StudentGrade tables.
/// </summary>
[FromTable("Course", Schema = "dbo")]
[JoinTable("StudentGrade", Schema = "dbo", JoinType = SqlJoinType.Left,
OnRaw = "Course.CourseID = StudentGrade.CourseID")]
public class CourseJoinTableJoinType
{
public int CourseID { get; set; }
public string Title { get; set; }
[SqlColumn("StudentGrade", column: "Grade")]
public decimal? Grade { get; set; }
}
}
Example Method:
using SnapObjects.Data;
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.JoinTableAttributeExamples
{
public class JoinTypeExample
{
private SchoolContext _context;
public JoinTypeExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Gets the SQL statement.
string sql = ModelSqlBuilder.GetBuilder<CourseJoinTableJoinType>(_context).QuerySql;
Console.WriteLine("SQL statement:");
Console.WriteLine(sql);
/* This code example produces the following output:
SQL statement:
SELECT
[dbo].[Course].[CourseID],
[dbo].[Course].[Title],
[StudentGrade].[Grade]
FROM [dbo].[Course]
LEFT JOIN [dbo].[StudentGrade]
ON [Course].[CourseID] = [StudentGrade].[CourseID]
*/
}
}
}
Applies to
.NET Standard
2.x