Даже можно не полностью описывать GetUsersResult. В-общем, вот полная программа для той же хранимки:
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Reflection;
namespace TestLinqStoredProcedures
{
class Program
{
static void Main(string[] args)
{
var context = new CustomDataContext("Data Source=localhost;Initial Catalog=Test;Integrated Security=True");
var result = context.GetUsers();
Console.WriteLine("Return value: {0}", (int)result.ReturnValue);
foreach (var record in result)
{
Console.WriteLine("UserID: {0}, Name: {1}", record.UserID, record.Name);
}
}
}
public class CustomDataContext : DataContext
{
private static MappingSource mappingSource = new AttributeMappingSource();
public CustomDataContext(string connection) : base(connection, mappingSource) { }
[Function(Name="dbo.GetUsers")]
public ISingleResult<GetUsersResult> GetUsers()
{
var result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult<GetUsersResult>)(result.ReturnValue));
}
}
public class GetUsersResult
{
private int _userID;
private string _name;
public int UserID
{
get { return _userID; }
set
{
if (_userID != value)
_userID = value;
}
}
public string Name
{
get { return _name; }
set
{
if (_name != value)
_name = value;
}
}
}
}
Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ~Martin Fowler
Данное сообщение получено с сайта GotDotNet.RU
Последний раз редактировалось 07 August 2008 13:19
|