I tried to solve this problem, but couldn't 그래서 다른 방법을 시도하고 있습니다.엔티티 프레임 워크입니다. 기본 키가없는 테이블을 올바르게 매핑하는 방법
주/외래 키가없는 3 개의 테이블로 구성된보기가 있습니다.
Product | Barcode
-------- | --------
product0 | barcode0
product1 | barcode1
product2 | barcode2
product2 | barcode2
지금, 어떻게 든 그룹을 필요 : 나는 행의이 같은를 가질 수 있도록
[Table("SkuBarcodesView")]
public partial class SkuBarcodesView
{
[Key]
[Column("_Code", Order = 0)]
[StringLength(11)]
public string C_Code { get; set; }
[Key]
[Column("_Description", Order = 1)]
[StringLength(150)]
public string C_Description { get; set; }
[Key]
[Column("_ProductCode", Order = 2)]
[StringLength(50)]
public string C_ProductCode { get; set; }
[Key]
[Column("_Ref", Order = 4)]
[StringLength(36)]
public string C_Ref { get; set; }
[Key]
[Column("_Barcode", Order = 5)]
public string C_Barcode { get; set; }
}
이 엔티티가 SKU-바코드 테이블을 나타냅니다
VS2015이 클래스를 생성합니다.
Severity Code Description Project File Line Suppression State
Error CS1061 'IGrouping' does not contain a definition for 'C_Barcode' and no extension method 'C_Barcode' accepting a first argument of type 'IGrouping' could be found (are you missing a using directive or an assembly reference?)
가 어떻게이 문제를 해결할 수 있습니다 : 나는이 오류를 참조
using (skumodel db = new skumodel())
{
var query = db.SkuBarcodesViews.GroupBy(e => e.C_Ref)
.Select(g => new { Barcode = g.C_Barcode });
}
을하지만 : 내가 노력하고있어?
이것은 시작에 불과합니다. EF를 통해 작업하고 싶은 키/외래 키가없는 많은 테이블이 데이터베이스에 있습니다.
키가없는 테이블에서 데이터를 가져 오는 올바른 방법은 무엇입니까? 이러한 테이블을 매핑하는 방법은 무엇입니까?
를? –
클래스가 ado.net 모델에 의해 자동 생성되었습니다. Btw 어떤 핵심 속성도없이 EntityType 'SkuBarcodesView'키가 정의되지 않았기 때문에 키와 같이 _ref 필드를 사용할 수 있습니다. 이 EntityType의 키를 정의하십시오. – zxyzxy
기존 데이터베이스를 사용하는 경우 코드 우선이 아닙니다. – Gasper