Home
Register
About
Login
Categories
C#
(13)
VB.NET
(0)
F#
(0)
ASP.NET
(15)
JavaScript
(4)
C++
(0)
C
(0)
Python
(0)
Ruby
(0)
Rails
(0)
J#
(0)
SQL
(0)
VB Script
(0)
HTML
(0)
CSS
(2)
XML
(2)
XSLT
(0)
Unit Testing
(7)
Architecture
(2)
Ajax
(0)
Project Management
(0)
LINQ to SQL
(2)
LINQ
(0)
LINQ to XML
(1)
NHibernate
(0)
Active Record
(0)
Silverlight
(0)
ASP.NET MVC
(0)
Life
(0)
Book Reviews
(0)
WPF
(1)
Visual Studio
(0)
Refering to a Single Entity in the List
by azamsharp on 7/29/2008 1:01:06 PM
I have two entities Employee and TimeCard. Employee can have multiple time cards. TimeCard has properties like CheckInTime and CheckOutTime.. When the employee check-in CheckInTime is updated with current time. When the employee check-out the same timecard CheckOutTime is update to the current time. Since, at given time an employee can only have one active time card I decided to use the following syntax to access the timcard. employee.TimeCards[0]; But I did not liked this approach so I chose a different approach as shown below.
public TimeCard CurrentTimeCard
{
get { return TimeCards[0]; }
}
// I run the tests like this:
// sam is an employee
[Test]
[RollBack]
public void a_time_card_is_created()
{
_repository.CheckIn(_sam);
Assert.IsNotNull(_sam.CurrentTimeCard);
}
Refactor it!
Please log in to refactor the code!
Login