本文整理汇总了C#中NorthwindEntities类的典型用法代码示例。如果您正苦于以下问题:C# NorthwindEntities类的具体用法?C# NorthwindEntities怎么用?C# NorthwindEntities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NorthwindEntities类属于命名空间,在下文中一共展示了NorthwindEntities类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:7,代码来源:EmpDetails.aspx.cs
示例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();
}
}
}
开发者ID:nim-ohtar,项目名称:TelerikAcademy-2,代码行数:29,代码来源:Program.cs
示例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();
}
}
开发者ID:nim-ohtar,项目名称:TelerikAcademy-2,代码行数:28,代码来源:CustomerControler.cs
示例4: ExecuteQueryForObjects
public object[] ExecuteQueryForObjects(XElement xml)
{
NorthwindEntities db = new NorthwindEntities();
IQueryable queryAfter = db.DeserializeQuery(xml);
return queryAfter.Cast<object>().ToArray();
throw new NotImplementedException();
}
开发者ID:JIANGSHUILANG,项目名称:TestSelfblog,代码行数:7,代码来源:NorthwindService.cs
示例5: Main
static void Main()
{
//NorthwindEntities dbContext = new NorthwindEntities();
using (var dbContext = new NorthwindEntities())
{
}
}
开发者ID:stoyanovalexander,项目名称:Projects,代码行数:7,代码来源:CreateDbContext.cs
示例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);
}
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:7,代码来源:ADO.cs
示例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)
{
}
}
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:25,代码来源:ADO.cs
示例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());
}
}
}
开发者ID:junxy,项目名称:EF_Caching_Demo,代码行数:35,代码来源:Program.cs
示例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();
}
}
开发者ID:Nikolay-D,项目名称:TelerikSchoolAcademy,代码行数:28,代码来源:NorthwindTwin.cs
示例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();
}
}
}
开发者ID:Nikolay-D,项目名称:TelerikSchoolAcademy,代码行数:28,代码来源:SameChanges.cs
示例11: GetCustomerAsync
public async Task<Customer> GetCustomerAsync(int id)
{
using (var ctx = new NorthwindEntities())
{
return await ctx.Customers.FindAsync(id);
}
}
开发者ID:kidroca,项目名称:Databases,代码行数:7,代码来源:DataAccessManager.cs
示例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
}
开发者ID:vvalotto,项目名称:PlataformaNET,代码行数:29,代码来源:Default.aspx.cs
示例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.");
}
}
开发者ID:C3co0o0o,项目名称:Databases,代码行数:35,代码来源:09.AddNewOrder.cs
示例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();
}
开发者ID:naynishchaughule,项目名称:ASP.NET,代码行数:7,代码来源:StoredProcDemo.aspx.cs
示例15: ModifyProductName
static void ModifyProductName(int productId, string newName)
{
NorthwindEntities northwindEntities = new NorthwindEntities();
Product product = GetProductById(northwindEntities, productId);
product.ProductName = newName;
northwindEntities.SaveChanges();
}
开发者ID:syssboxx,项目名称:SchoolAcademy,代码行数:7,代码来源:UpdatingDeletingInsertingData.cs
示例16: DeleteProduct
static void DeleteProduct(int productId)
{
NorthwindEntities northwindEntities = new NorthwindEntities();
Product product = GetProductById(northwindEntities, productId);
northwindEntities.Products.Remove(product);
northwindEntities.SaveChanges();
}
开发者ID:syssboxx,项目名称:SchoolAcademy,代码行数:7,代码来源:UpdatingDeletingInsertingData.cs
示例17: Main
public static void Main()
{
using (var dbNorthwnd = new NorthwindEntities())
{
// Task 2. Create a DAO class with static methods which provide functionality for inserting, modifying and deleting customers.
// START JUST ONE TIME - otherwise throw exception, because it creates customers with the same id number.
// ADO.AddCustomer(dbNorthwnd, "1");
// ADO.AddCustomer(dbNorthwnd, "2");
// ADO.ModifyCustomer(dbNorthwnd);
// ADO.DeleteCustomer(dbNorthwnd);
// Task 3. Write a method that finds all customers who have orders made in 1997 and shipped to Canada.
FindCustomersWithOrdersFrom1997ToCanada(dbNorthwnd);
Console.WriteLine();
// Task 4. Implement previous by using native SQL query and executing it through the DbContext.
Console.WriteLine("Task 4");
FindCustomersWithOrdersFrom1997ToCanadaWithNativeSQL(dbNorthwnd);
Console.WriteLine();
// Task 5. Write a method that finds all the sales by specified region and period (start / end dates).
Console.WriteLine("Task 5");
FindSalesByRegionAndPeriod(dbNorthwnd, "Canada", new DateTime(1996, 10, 10), new DateTime(1997, 10, 10));
}
}
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:25,代码来源:WorkWithNortwnd.cs
示例18: FindSpecificSales
public static void FindSpecificSales(string region = null, string startDate = null, string endDate = null)
{
using (NorthwindEntities dbContext = new NorthwindEntities())
{
DateTime startDateParsed = DateTime.Parse(startDate);
DateTime endDateParsed = DateTime.Parse(endDate);
var selectedSales =
from sale in dbContext.Orders
where (sale.ShipRegion == region) && (sale.OrderDate > startDateParsed && sale.OrderDate < endDateParsed)
orderby sale.ShipCity, sale.OrderDate, sale.ShippedDate
select new
{
OrderDate = sale.OrderDate,
ShippedDate = sale.ShippedDate,
City = sale.ShipCity
};
int counter = 0;
Console.WriteLine("Region - {0}", region ?? "No region");
Console.WriteLine("Start date - {0}", startDateParsed);
Console.WriteLine("End date - {0}", endDateParsed);
Console.WriteLine(new string('-', 50));
Console.WriteLine();
foreach (var sale in selectedSales)
{
counter++;
Console.WriteLine("{0}. City: {1} || Order date: {2} || Shipped date: {3}", counter, sale.City, sale.OrderDate, sale.ShippedDate);
}
}
}
开发者ID:Nikolay-D,项目名称:TelerikSchoolAcademy,代码行数:31,代码来源:SpecificSales.cs
示例19: Main
static void Main(string[] args)
{
Customer newCustmer = new Customer();
newCustmer.CustomerID = "KULO";
newCustmer.CompanyName = "Mala";
newCustmer.ContactName = "Misoto Kulano";
newCustmer.ContactTitle = "Owner";
newCustmer.Address = "Amela str 23";
newCustmer.City = "Pelon";
newCustmer.PostalCode = "1231";
newCustmer.Country = "France";
newCustmer.Phone = "3443-4323-432";
newCustmer.Fax = "3245-243";
using (var otherDataBase = new NorthwindEntities())
{
using (var dataBase = new NorthwindEntities())
{
otherDataBase.Customers.Add(newCustmer);
otherDataBase.SaveChanges();
//Customer customer = dataBase.Customers.First(x => x.CustomerID == "KULO");
dataBase.Customers.Attach(newCustmer);
dataBase.Customers.Remove(newCustmer);
dataBase.SaveChanges();
}
}
}
开发者ID:Gerya,项目名称:TelerikAcademy,代码行数:28,代码来源:SameChanges.cs
示例20: GetAllCustomersAsync
public async Task<Customer[]> GetAllCustomersAsync()
{
using (var ctx = new NorthwindEntities())
{
return await ctx.Customers.ToArrayAsync();
}
}
开发者ID:kidroca,项目名称:Databases,代码行数:7,代码来源:DataAccessManager.cs
注:本文中的NorthwindEntities类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论