It's time to complicate an example.
First of all I'm going to assign database table to our entity. In the previous examples, we have to specify table in From method. To avoid this we should mark entity class with EntityAttribute attribute.
[Entity("Sales", "Store", "1")]
Here we specify Sales database schema and Store table name. 1 - entity schema version (forget it
).
The next improvment - implement static Query property returns QueryCmd instance.
[Entity("Sales", "Store", "1")]
public class Store3
{
[EntityProperty("CustomerID", Field2DbRelations.PK)]
public int ID { get; set; }
public string Name { get; set; }
public DateTime ModifiedDate { get; set; }
public XmlDocument Demographics { get; set; }
[EntityProperty("rowguid", Field2DbRelations.RowVersion)]
public Guid Timestamp { get; protected set; }
public int SalesPersonID { get; set; }
public static QueryCmd Query
{
get
{
return new QueryCmd(exam1sharp.Properties.Settings.Default.connString)
.From(typeof(Store3))
.Select(typeof(Store3));
}
}
}
The program prints stores whos name starts with A.
static void Main5(string[] args)
{
foreach (Store3 s in Store3.Query
.Where(Ctor.prop(typeof(Store3), "Name").like("A%"))
.ToList())
{
Console.WriteLine("Store id: {0}, name: {1}, timestamp: {2}", s.ID, s.Name, s.Timestamp);
}
}