当前位置: 首页>>代码示例>>C#>>正文


C# NorthwindEntities类代码示例

本文整理汇总了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();
 }
开发者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


注:本文中的NorthwindEntities类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。