static void Main(string[] args)
{
Class1 c = new Class1();
string s= c.GetShipper();
Console.Write(s);
Console.ReadLine();
}
class Class1
{
public string GetShipper()
{
StringBuilder sb = new StringBuilder();
using (var ctx = new NORTHWNDEntities())
{
var idParam = new SqlParameter
{
ParameterName = "ShipperID",
Value = 1
};
var ShipperList = ctx.Database.SqlQuery<Shipper>("exec GetShippers @ShipperID ", idParam).ToList<Shipper>();
foreach (Shipper s in ShipperList)
{
sb.Append(s.CompanyName + ",");
}
return sb.ToString();
}
}
}
public partial class Shipper
{
public Shipper()
{
this.Orders = new HashSet<Order>();
}
public int ShipperID { get; set; }
public string CompanyName { get; set; }
public string Phone { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
public partial class NORTHWNDEntities : DbContext
{
public NORTHWNDEntities()
: base("name=NORTHWNDEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<CustomerDemographic> CustomerDemographics { get; set; }
public virtual DbSet<Customer> Customers { get; set; }
public virtual DbSet<Employee> Employees { get; set; }
public virtual DbSet<Order_Detail> Order_Details { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Region> Regions { get; set; }
public virtual DbSet<Shipper> Shippers { get; set; }
public virtual DbSet<Supplier> Suppliers { get; set; }
public virtual DbSet<sysdiagram> sysdiagrams { get; set; }
public virtual DbSet<Territory> Territories { get; set; }
}
27 July 2017
Executing stored procedure / SQL through entity framework (based on the Northwind database)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment