本文整理汇总了C#中NorthwindEntities类的典型用法代码示例。如果您正苦于以下问题:C# NorthwindEntities类的具体用法?C# NorthwindEntities怎么用?C# NorthwindEntities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NorthwindEntities类属于命名空间,在下文中一共展示了NorthwindEntities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var db = new NorthwindEntities();
var id = int.Parse(Request.QueryString["id"]);
this.EmployeeDetailView.DataSource = db.Employees.Where(em => em.EmployeeID == id).ToList();
Page.DataBind();
}
示例2: PlaceNewOrder
static void PlaceNewOrder(string customerId,int employeeId,Order_Detail[] details)
{
using (NorthwindEntities nwDb = new NorthwindEntities())
{
using (TransactionScope scope = new TransactionScope())
{
Order order = new Order
{
CustomerID = customerId,
EmployeeID = employeeId,
ShipVia = 1,
ShipName = "UnknownShip",
ShipAddress = "UnknownAddress",
ShipCity = "Unknown",
ShipRegion = "Unknown",
ShipPostalCode = "121311",
ShipCountry = "Unknown",
Order_Details = details
};
nwDb.Orders.Add(order);
nwDb.SaveChanges();
scope.Complete();
}
}
}
示例3: InsertCustomer
public static void InsertCustomer(string customerId, string companyName, string contactName, string contactTitle,
string adress, string city, string region, string postalCode, string country, string phone, string fax)
{
if (customerId.Length == 0 || customerId.Length>5)
{
throw new ArgumentException("The lenght of CustomerId must be between 0 and 5 characters!");
}
using (NorthwindEntities nwDb = new NorthwindEntities())
{
Customer cusomer = new Customer
{
CustomerID = customerId,
CompanyName = companyName,
ContactName = contactName,
ContactTitle = contactTitle,
Address = adress,
City = city,
Region = region,
PostalCode = postalCode,
Country = country,
Phone = phone,
Fax = fax
};
nwDb.Customers.Add(cusomer);
nwDb.SaveChanges();
}
}
示例4: ExecuteQueryForObjects
public object[] ExecuteQueryForObjects(XElement xml)
{
NorthwindEntities db = new NorthwindEntities();
IQueryable queryAfter = db.DeserializeQuery(xml);
return queryAfter.Cast<object>().ToArray();
throw new NotImplementedException();
}
示例5: Main
static void Main()
{
//NorthwindEntities dbContext = new NorthwindEntities();
using (var dbContext = new NorthwindEntities())
{
}
}
示例6: DeleteCustomer
public static void DeleteCustomer(NorthwindEntities dbNorthwnd)
{
var customer = dbNorthwnd.Customers.Where(z => z.CustomerID == "AAAA1").First();
dbNorthwnd.Customers.Remove(customer);
var affectedRows = dbNorthwnd.SaveChanges();
Console.WriteLine("({0} row(s) affected)", affectedRows);
}
示例7: AddCustomer
public static void AddCustomer(NorthwindEntities dbNorthwnd, string name)
{
var customer = new Customer()
{
CustomerID = "AAAA" + name,
CompanyName = "YYYY" + name,
ContactName = "Pesho Peshev",
ContactTitle = "Shef",
Address = "aaaaaaaaaa",
City = "Sofia",
PostalCode = "1330",
Country = "Bulgaria",
Phone = "0000000",
Fax = "0000000"
};
dbNorthwnd.Customers.Add(customer);
try
{
dbNorthwnd.SaveChanges();
}
catch (Exception ex)
{
}
}
示例8: Main
static void Main(string[] args)
{
EFTracingProviderConfiguration.RegisterProvider();
EFCachingProviderConfiguration.RegisterProvider();
//ICache cache = new InMemoryCache();
ICache cache = MemcachedCache.CreateMemcachedCache();
CachingPolicy cachingPolicy = CachingPolicy.CacheAll;
// log SQL from all connections to the console
EFTracingProviderConfiguration.LogToConsole = true;
for (int i = 0; i < 3; i++)
{
Console.WriteLine();
Console.WriteLine("*** Pass #{0}...", i);
Console.WriteLine();
using (var nDb = new NorthwindEntities())
{
nDb.Cache = cache;
nDb.CachingPolicy = cachingPolicy;
var emp = nDb.Customers.First(x => x.CustomerID == "ALFKI");
Console.WriteLine(nDb.Customers.First(x => x.CustomerID == "ALFKI").ContactName);
Console.WriteLine(nDb.Customers.First(x => x.CustomerID == "ALFKI").ContactName);
Console.WriteLine(nDb.Customers.First().ContactName);
Console.WriteLine(nDb.Customers.First().ContactName);
Console.WriteLine(nDb.Customers.AsNoTracking().First(x => x.CustomerID == "ALFKI").Orders.Count());
}
}
}
示例9: Main
static void Main()
{
IObjectContextAdapter context = new NorthwindEntities();
string northwindScript = context.ObjectContext.CreateDatabaseScript();
string createNorthwindCloneDB = "USE master; " +
"CREATE DATABASE NorthwindTwin; " +
"SELECT name, size, size*1.0/128 AS [Size in MBs] " +
"FROM sys.master_files " +
"WHERE name = NorthwindTwin; ";
SqlConnection dbConnection = new SqlConnection("Server=NIKOLAI\\SQLEXPRESS; " +
"Database=master; " +
"Integrated Security=true");
dbConnection.Open();
using (dbConnection)
{
SqlCommand cmd = new SqlCommand(createNorthwindCloneDB, dbConnection);
cmd.ExecuteNonQuery();
string changeToNorthwind = "Use NorthwindTwin";
SqlCommand changeDBCmd = new SqlCommand(changeToNorthwind, dbConnection);
changeDBCmd.ExecuteNonQuery();
SqlCommand cloneDB = new SqlCommand(northwindScript, dbConnection);
cloneDB.ExecuteNonQuery();
}
}
示例10: Main
// First way
static void Main()
{
using (NorthwindEntities firstDB = new NorthwindEntities())
{
using (NorthwindEntities secondDB = new NorthwindEntities())
{
var firstCustomer =
(from c in firstDB.Customers
where c.CustomerID == "PARIS"
select c).First();
var secondCustomer =
(from c in secondDB.Customers
where c.CustomerID == "PARIS"
select c).First();
firstCustomer.CompanyName = "First Change with LINQ";
secondCustomer.ContactName = "Second Change with LINQ";
firstDB.SaveChanges();
secondDB.SaveChanges();
Console.WriteLine("Changes are made successfully!");
//SecondWayForChangeRecords();
}
}
}
示例11: GetCustomerAsync
public async Task<Customer> GetCustomerAsync(int id)
{
using (var ctx = new NorthwindEntities())
{
return await ctx.Customers.FindAsync(id);
}
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
NorthwindEntities context = new NorthwindEntities();
#region forma 1
var datos = from entidadCustomers in context.Customers
where entidadCustomers.Orders.Count() > 10
select new
{
customerId = entidadCustomers.CustomerID,
companyName = entidadCustomers.CompanyName,
orders = entidadCustomers.Orders.Count()
};
GridView1.DataSource = datos;
GridView1.DataBind();
#endregion forma 1
#region forma 2
var datos2 = context.Customers.Where(x => x.Orders.Count > 10);
GridView2.DataSource = datos2;
GridView2.DataBind();
#endregion forma 2
}
示例13: InsertOrder
static void InsertOrder(
string shipName, string shipAddress,
string shipCity, string shipRegionm,
string shipPostalCode,string shipCountry,
string customerID = null, int? employeeID = null,
DateTime? orderDate = null, DateTime? requiredDate = null,
DateTime? shippedDate = null, int? shipVia = null,
decimal? freight = null)
{
using (NorthwindEntities context = new NorthwindEntities())
{
Order newOrder = new Order
{
ShipAddress = shipAddress,
ShipCity = shipCity,
ShipCountry = shipCountry,
ShipName = shipName,
ShippedDate = shippedDate,
ShipPostalCode = shipPostalCode,
ShipRegion = shipRegionm,
ShipVia = shipVia,
EmployeeID = employeeID,
OrderDate = orderDate,
RequiredDate = requiredDate,
Freight = freight,
CustomerID = customerID
};
context.Orders.Add(newOrder);
context.SaveChanges();
Console.WriteLine("Row is inserted.");
}
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
NorthwindEntities objectContext = new NorthwindEntities();
var result = objectContext.SelectCategory(65985);
GridView1.DataSource = result;
GridView1.DataBind();
}
示例15: ModifyProductName
static void ModifyProductName(int productId, string newName)
{
NorthwindEntities northwindEntities = new NorthwindEntities();
Product product = GetProductById(northwindEntities, productId);
product.ProductName = newName;
northwindEntities.SaveChanges();
}