FromTableAttribute.WhereRaw Property
.NET Standard 2.x | Current Version (1.0.1)
Gets or sets the raw SQL WHERE clause for the database table.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public string WhereRaw { get; set; }
Property Value Type
System.String
The raw WHERE clause for the database table.
Examples
The following code example demonstrates how to use the WhereRaw property of the FromTable Attribute.
Model: PersonFromTableWhereRaw
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.Models.School
{
/// <summary>
/// This model class maps to the dbo.Person table.
/// </summary>
[FromTable("Person", Schema = "dbo", WhereRaw = "PersonID < 10")]
public class PersonFromTableWhereRaw
{
public Int32 PersonID { get; set; }
public String LastName { get; set; }
public String FirstName { get; set; }
public DateTime? HireDate { get; set; }
public DateTime? EnrollmentDate { get; set; }
public String Discriminator { get; set; }
}
}
Example Method:
using SnapObjects.Data;
using Appeon.ApiDoc.Models.School;
using System;
namespace Appeon.ApiDoc.FromTableAttributeExamples
{
public class WhereRawExample
{
private SchoolContext _context;
public WhereRawExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Gets the SQL Select statement.
string sql = ModelSqlBuilder.GetBuilder<PersonFromTableWhereRaw>(_context).QuerySql;
Console.WriteLine("SQL statement:");
Console.WriteLine(sql);
/* This code example produces the following output:
SQL statement:
SELECT
[PersonID],
[LastName],
[FirstName],
[HireDate],
[EnrollmentDate],
[Discriminator]
FROM [dbo].[Person]
WHERE ([PersonID] < 10)
*/
}
}
}
Applies to
.NET Standard
2.x