Reputation: 1732
I've started playing around with using Entity Framework Code-First because it looks like a nice way to get a database up and running quickly. I'm coming from a PostgreSQL background, which has support for array types in tables, for example time[]
. My question is two-fold; does SQL Server support array types, and if so, how can I use them in EF? If they're not supported, what is an alternative way to represent this data?
table Venue
openhours time[]
Edit: The array above is intended to store different times for each day of the week- a venue might have different opening hours on different weekends to weekdays, for example.
Upvotes: 0
Views: 2197
Reputation: 2203
SQL Server doesn't support array types. Extrapolating from your example schema, I think an equivalent EF POCO would be the following:
public class Venue
{
public int VenueId { get; set; }
public DateTime OpenHour { get; set; }
public DateTime CloseHour { get; set; }
}
Finding whether the Venue
was open at a given time would just require a range query, Venue.Where(a => a.OpenHour <= time && a.CloseHour >= time)
. Of course, this is a very simplistic example. Most likely you'd want to store the Venue hours in another table. But I hope this may be able to move you in the right direction.
Upvotes: 1
Reputation: 47038
No, it is not supported, you need to store your openhours
in a separate table (VenueOpenhours
) with a foreign key to the Venue
table.
Upvotes: 1