Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are related records loaded into HashSet or SortedSet?

Assume we have POCO class for Entity Framework 4:

public class Order
{
    public long Id { get; set; }
    public ISet<OrderItem> OrderItems { get; set; }
}

And this method to retrieve the order from database:

public Order GetOrder(long orderId)
{
    using (var context = new MyModelEntities())
    {
        return context.Orders.Include("OrderItems").Where(order => order.Id == orderId).FirstOrDefault();
    }
}

So suppose we do this:

Order myOrder = GetOrder(1);

Is myOrder.OrderItems a HashSet or SortedSet? Is there a way to control this?

like image 687
niaher Avatar asked Dec 16 '25 16:12

niaher


1 Answers

Good question.

As far as i know (and there is no MSDN/blog/article i am aware of that dispells/proves this), a navigational property can be of any type as long as it implements ICollection<T>.

Both HashSet<T> and SortedSet<T> implement ICollection<T>, so either would be viable candidates.

Did you step through the code? You should be able to see which concrete class get's resolved.

Most people use ICollection<T> / IList<T>. Why are you wanting to declare the property as ISet<T>?

Why don't you just declare which type you want, instead of the interface.

Or you could try using dependency injection (For<ISet>().Use<HashSet>()).

like image 87
RPM1984 Avatar answered Dec 19 '25 05:12

RPM1984



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!