를 이용 COL 목록을 반복 열 :업데이트 엔티티 나는이 같은 LINQ를 사용하여 테이블에서 열 목록을 얻을 수 있습니다 LINQ
OrderDataContext ctx = new OrderDataContext();
var cols = ctx.Mapping.MappingSource
.GetModel(typeof(OrderDataContext))
.GetMetaType(typeof(ProductInformation))
.DataMembers;
이 나에게 열 목록을 제공합니다, 그래서 나는이 작업을 수행 할 수 있습니다
foreach (var col in cols)
{
// Get the value of this column from another table
GetPositionForThisField(col.Name);
}
이 모든 것이 작동하므로 열 이름이 다른 테이블의 키이기 때문에 열 목록을 반복하고 그 열의 값을 다른 테이블에서 가져올 수 있으므로 전환 할 필요가 없습니다. .. 또는 많은 경우 ... 다음 ...
이제 질문 :
이 값을 얻은 후에 엔티티를 다시 저장하기 위해 엔티티를 채우는 방법은 무엇입니까? 나는 일반적으로 다음과 같이 갈 것 :
ProductInformation info = new ProductInformation();
info.SomeField1 = val1;
info.SomeField2 = val2;
ctx.ProductInformation.InsertOnSubmit(info);
ctx.SubmitChanges();
하지만 어떻게 그 반복하면서 열을 채우기 위해 위의 같은 열 컬렉션을 사용하여, 같은 것은 존재하지 않는 경우 :
info["field1"].Value = val1;
감사합니다.