Я занимаюсь разработкой веб-приложения. Я хочу автоматизировать класс своей корзины.
Asp.net Mvc FluentNhibernate
Класс My Cart ------------------------
public class Cart : IEntity
{
public virtual int CartId { get; set; }
public
List<CartLine> _cartLines = new List<CartLine>();
public void AddToCart(Product product, int quantity)
{
CartLine cartLine = _cartLines.FirstOrDefault(c =>
c.Product.ProductId == product.ProductId);
if (cartLine == null)
{
_cartLines.Add(new CartLine { Product = product, Qunatity = quantity });
}
else
{
cartLine.Qunatity += quantity;
}
}
public void RemoveFromCart(Product product)
{
_cartLines.RemoveAll(p => p.Product.ProductId == product.ProductId);
}
public decimal Total
{
get
{
return _cartLines.Sum(c => c.Product.UnitPrice * c.Qunatity);
}
}
public void Clear()
{
_cartLines.Clear();
}
public List<CartLine> Lines
{
get
{
return _cartLines;
}
}
}
public class CartLine
{
public Product Product { get; set; }
public int Qunatity { get; set; }
}
}
Моя конфигурация автоматического сопоставления -------
public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool IsId(Member member)
{
if (member.Name == "CustomerTypeId")
{
return true;
}
return member.Name == member.DeclaringType.Name + "Id";
}
public override bool ShouldMap(Member member)
{
if (member.MemberInfo.ReflectedType.FullName.Contains("Entities.Concrete"))
{
return base.ShouldMap(member);
}
return false;
}
public override bool ShouldMap(Type type)
{
return type.Namespace != null && type.Namespace.Contains("Entities.Concrete");
}
}
Моя конфигурация сопоставления -------
.Mappings (d => d.AutoMappings.Add (AutoMap.AssemblyOf (new AutomappingConfiguration ()). Conventions.Add () .Conventions.Add () .Conventions.Add (FluentNHibernate.Conventions.Helpers.DefaultLazy.Never ())
The entity '<>c' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).
Name = "<> c" FullName = "MyShop.Northwind.Entities.Concrete.Cart+<>c
"} System.Type {System.RuntimeType}