제가하려는 것은 WCF 서비스를 사용하여 하나의 데이터베이스 (트랜잭션)를 사용하는 방법을 만드는 것입니다. 날짜, 다음 등 이익, 매일 takings, 비용을 표시하는 날짜별로 하나 개의 행이됩니다 내 일일 매출 테이블에 추가는WCF 서비스를 사용하여 LINQ to SQL을 사용하여 SQL 데이터베이스의 단일 행을 업데이트하려고합니다.
나는이
public void CalculateProfit(string Date)
{
decimal takings = 0;// not needed
decimal Expenses = 0;// not needed
using (transactionClassDataContext cont = new transactionClassDataContext())
{
int counter = 0;
DailySale d = new DailySale();
var query = (from q in cont.DailySales where q.Date.Equals(Date) select q);
var query2 = (from r in cont.Transactions where r.Date.Equals(Date) select r);
foreach (var z in query)
{
counter++;
}
if (counter>0)
{
foreach (var y in query2)
{
takings = takings + y.Price;
Expenses = Expenses + 0;
d.Expenses += 0;
d.Takings += y.Price;
d.Profit = d.Takings - d.Expenses;
d.Date = Date;
cont.DailySales.InsertOnSubmit(d);// update the value
cont.SubmitChanges();
}
}
else
{
d.Date = Date;
cont.DailySales.InsertOnSubmit(d);// if there isnt an entry for todays date, add one
cont.SubmitChanges();
}
}
}
}
}
처럼하려고 노력했습니다 그러나이 모든 것은 "이미 존재하는 엔티티를 추가 할 수 없습니다."라는 오류를 발생시킵니다.
foreach에서 d의 새 인스턴스를 만들 필요가 있다고 말했지만, 원하는 모든 작업이 업데이트 된 총 하나의 행일 때 m 개의 일일 판매에 많은 양의 레코드를 추가하는 것만 같습니다.
아이디어가 있으십니까?
질문을 읽으면 답이 내 문제를 해결하지 못할 수도 있습니다. –