﻿//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a CodeSmith Template.
//
//     DO NOT MODIFY contents of this file. Changes to this
//     file will be lost if the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdventureWorks.Data.Queries
{
    public static partial class CurrencyRateExtensions
    {

        /// <summary>
        /// Gets an instance by the primary key.
        /// </summary>
        public static AdventureWorks.Data.Entities.CurrencyRate GetByKey(this System.Linq.IQueryable<AdventureWorks.Data.Entities.CurrencyRate> queryable, int currencyRateID)
        {
            var dbSet = queryable as System.Data.Entity.IDbSet<AdventureWorks.Data.Entities.CurrencyRate>;
            if (dbSet != null)
                return dbSet.Find(currencyRateID);
                
            return queryable.FirstOrDefault(c => c.CurrencyRateID == currencyRateID);
        }

        /// <summary>
        /// Gets an instance by using a unique index.
        /// </summary>
        /// <returns>An instance of the entity or null if not found.</returns>
        public static AdventureWorks.Data.Entities.CurrencyRate GetByCurrencyRateDateFromCurrencyCodeToCurrencyCode(this IQueryable<AdventureWorks.Data.Entities.CurrencyRate> queryable, System.DateTime currencyRateDate, string fromCurrencyCode, string toCurrencyCode)
        {
            return queryable.FirstOrDefault(c => c.CurrencyRateDate == currencyRateDate
                && c.FromCurrencyCode == fromCurrencyCode
                && c.ToCurrencyCode == toCurrencyCode);
        }

        public static IQueryable<AdventureWorks.Data.Entities.CurrencyRate> ByFromCurrencyCode(this IQueryable<AdventureWorks.Data.Entities.CurrencyRate> queryable, string fromCurrencyCode)
        {
            return queryable.Where(c => c.FromCurrencyCode == fromCurrencyCode);
        }

        public static IQueryable<AdventureWorks.Data.Entities.CurrencyRate> ByToCurrencyCode(this IQueryable<AdventureWorks.Data.Entities.CurrencyRate> queryable, string toCurrencyCode)
        {
            return queryable.Where(c => c.ToCurrencyCode == toCurrencyCode);
        }
    }
}
