HasKey бросает InvalidOperationException - это ошибка в Entity Framework Code First?

Хорошо, я смотрю на экран уже пару часов и понятия не имею, почему я получаю эту ошибку. Я использовал Code First в ряде других проектов и не имел проблем с этим раньше...

Вот ошибка:

System.InvalidOperationException was unhandled by user code
  Message=The properties expression 'sci => sci.ShoppingCartItemId' is not valid. The expression should represent a property: C#: 't => t.MyProperty'  VB.Net: 'Function(t) t.MyProperty'. When specifying multiple properties use an anonymous type: C#: 't => new { t.MyProperty1, t.MyProperty2 }'  VB.Net: 'Function(t) New From { t.MyProperty1, t.MyProperty2 }'.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.ModelConfiguration.Utilities.ExpressionExtensions.GetSimplePropertyAccessList(LambdaExpression propertyAccessExpression)
       at System.Data.Entity.ModelConfiguration.EntityTypeConfiguration`1.HasKey[TKey](Expression`1 keyExpression)
       at BillingPlatform.DataLayer.BillingDb.OnModelCreating(DbModelBuilder modelBuilder) in [somepath]\BillingDb.cs:line 57
       at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
       at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
       at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
  InnerException: 

Вот код, который выдает ошибку. Первая строка:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{                       
   modelBuilder.Entity<ShoppingCartItem>().HasKey(sci => sci.ShoppingCartItemId);
   modelBuilder.Entity<Product>().HasKey<Guid>(p => p.ProductId);
   modelBuilder.Entity<DependentItemType>().HasKey<Guid>(dit => dit.DependentItemTypeId);
   modelBuilder.Entity<ProductCategory>().HasKey<Guid>(pc => pc.ProductCategoryId);

   base.OnModelCreating(modelBuilder);
}

Здесь просто класс ShoppingCartItem в качестве ссылки:

namespace BillingPlatform.Libraries
{
    public class ShoppingCartItem
    {
        /// <summary>
        /// The unique identifier of this shopping cart item.
        /// </summary>        
        public Guid ShoppingCartItemId { get; set; }

        public Product Product { get; set; }

        public decimal Price { get; set; }

        public decimal Tax { get; set; }

        public Guid UserId { get; set; }

        public bool InCart { get; set; }

        public string ProductData { get; set; }

        public DependentItemType DependentItemType { get; set; }

        public string DependentItemId { get; set; }
    }
}

Кто-нибудь понимает, почему Entity Framework может выдать эту ошибку? Мое лямбда-выражение:

modelBuilder.Entity<ShoppingCartItem>().HasKey(s => s.ShoppingCartItemId);

очень простое. Я не понимаю, что может идти не так... Спасибо за любую помощь!

10
задан Ayo I 22 January 2012 в 08:54
поделиться