i’ve started working with ASP.NET MVC and using Entity Framework, concretely with SQLite db,
but i’ve got a little problem:
I’ve got a one to many relation, but EF generates wrong query,
SQLite error
no such column: Extent1.Category_CategoryID
so, he uses ModelName as a prefix and it’s wrong.
Is there any convention, which i can remove? Or set off?
thx and sorry for my bad english
// Update, added Category entity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace Eshop.Domain.Entities
{
[Table("Categories")]
public class Category
{
public Int64 CategoryID { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
}
// added Product entity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
namespace Eshop.Domain.Entities
{
[Table("Products")]
public class Product
{
public Int64 ProductID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int CategoryID { get; set; }
}
}
If you are using Code-First (which I assume) you need to…
either introduce a navigation property in
Product:EF will recognize
CategoryIDas foreign key then.or configure
CategoryIDas foreign key with Fluent API: