SQL サーバー データベースと通信する単純な ASP.NET アプリケーションを構築しています。別のプロジェクトには、Visual Studio によって生成されたデータセットがあります。データベース内のすべてのユーザーを表示する API を公開しようとしていますが、例外が発生します。
コードは次のとおりです。
public class UserController : ApiController {
public IEnumerable<GWDataSet.usersRow> GetAllUsers() {
GWDataSet gw = new GWDataSet();
usersTableAdapter adapter = new usersTableAdapter();
adapter.Fill(gw.users);
return gw.users.AsEnumerable();
}
}
そして、これは例外です:
Type 'System.Data.DataRow' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
システム生成コードを手動で編集する以外に、これを回避する方法はありますか? 次回データセットに変更を加えると、追加したすべての datacontract 要素が上書きされるのではないかと心配しています。これを行う方法があると思いますが、見つけられないようです。
ありがとう!