public IActionResult mostrar() { using (var db = new LinqContext()) { // Sacando todos los datos var mostrarTodos = db.software.OrderByDescending(x => x.nombre).ThenBy(x => x.os).ToList(); ViewData["programa"] = mostrarTodos; // Sacando solo un dato var soloUno = db.software.Where(x => x.nombre.StartsWith("ñ")); if (soloUno != null) { ViewData["individual"] = "No hay valor encontrado"; if (true) { foreach (var item in soloUno) { ViewData["individual"] = item.nombre; } } } } return(View()); }
public IActionResult insertar() { using (var db = new LinqContext()) { var sistemax = new software(); var sistemax2 = new software(); var sietmeax3 = new software(); sistemax.os = "Linux"; sistemax.nombre = "Atom"; sistemax.precio = 30; sistemax2.os = "Windos"; sistemax2.nombre = "Visual"; sistemax2.precio = 0; sietmeax3.os = "Os X"; sietmeax3.nombre = "Sublime text"; sietmeax3.precio = 100; var lista = new List <software>() { sistemax, sistemax2, sietmeax3 }; db.software.AddRange(lista); db.SaveChanges(); } return(View()); }
public LinqOperator(IQueryable <TEntity> dataSet) { _context = new LinqContext <TEntity> { DataSet = dataSet, DataSetType = typeof(TEntity), ParameterExpression = Expression.Parameter(typeof(TEntity), "e") }; }
static void Main(string[] args) { LinqContext context = new LinqContext(); var categories = from c in context.Categories select c; Console.WriteLine("All categories"); Console.WriteLine("{0, -10} {1, 10}", "Id", "Name"); foreach (var item in categories) { Console.WriteLine("{0, -10} {1, 10}", item.CategoryId, item.Name); } var categoryWithProducts = from c in context.Categories join p in context.Products on c.CategoryId equals p.CategoryId select new { CategoryId = c.CategoryId, CategoryName = c.Name, ProductName = p.Name != null ? p.Name : "" }; Console.WriteLine("Categories with products"); Console.WriteLine("{0, -10} {1, 10} {2, 20}", "Id", "Name", "Product"); foreach (var item in categoryWithProducts) { Console.WriteLine("{0, -10} {1, 10} {2, 20}", item.CategoryId, item.CategoryName, item.ProductName); } Console.WriteLine("All categories and their products"); var categoryWithEmptyProducts = from c in context.Categories join p in context.Products on c.CategoryId equals p.CategoryId into cp from x in cp.DefaultIfEmpty() select new { CategoryId = c.CategoryId, CategoryName = c.Name, ProductName = x.Name != null ? x.Name : "" }; Console.WriteLine("{0, -10} {1, 10} {2, 20}", "Id", "Name", "Product"); foreach (var item in categoryWithEmptyProducts) { Console.WriteLine("{0, -10} {1, 10} {2, 20}", item.CategoryId, item.CategoryName, item.ProductName); } Console.WriteLine("Products by Category"); var productsByCategory = from c in context.Categories join p in context.Products on c.CategoryId equals p.CategoryId into cp from x1 in cp group c by x1.Category.Name into g select new { CategoryId = g.Key, Count = g.Count() != null?g.Count() : 0 }; Console.WriteLine("{0, -10} {1, 10}", "Name", "Count"); foreach (var item in productsByCategory) { Console.WriteLine("{0, -10} {1, 10}", item.CategoryId, item.Count); } Console.ReadKey(); }
public override object VisitLinq([NotNull] LinqContext context) { var r = new Result { data = "var" }; r.text += "from " + ((Result)Visit(context.expression(0))).text + " "; foreach (var item in context.linqItem()) { r.text += (string)Visit(item) + " "; } r.text += context.k.Text + " " + ((Result)Visit(context.expression(1))).text; return(r); }
public override object VisitLinq(LinqContext context) { var r = (new Result() { data = "var" }); r.text += (string)(Visit(context.linqHeadItem())); foreach (var item in context.linqItem()) { r.text += (new System.Text.StringBuilder().Append(Visit(item)).Append(" ")).to_str(); } r.text += (new System.Text.StringBuilder().Append(((Result)(Visit(context.id()))).text).Append(" ").Append(((Result)(Visit(context.expression()))).text)).to_str(); return(r); }
private static void TestSchoolModel() { using (var db = new LinqContext()) { var course = new Course { Title = "Biology 101" }; var fred = new Instructor { Name = "Fred Jones" }; var julia = new Instructor { Name = "Julia Canfield" }; var section1 = new Section { Course = course, Instructor = fred }; var section2 = new Section { Course = course, Instructor = julia }; //var jim = new Student { Name = "Jim Roberts" }; //jim.sections.Add(section1); //var jerry = new Student { Name = "Jerry Jones" }; //jerry.Sections.Add(section2); //var susan = new Student { Name = "Susan O'Reilly" }; //susan.Sections.Add(section1); //var cathy = new Student { Name = "Cathy Ryan" }; //cathy.Sections.Add(section2); //db.Students.Add(jim); //db.Students.Add(jerry); //db.Students.Add(cathy); //db.Students.Add(susan); //db.SaveChanges(); } }
public ProductStockDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public CategoryDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public WorkPlaceDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public IncomeDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public DebtorCreditorsDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public DailyBalanceDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
private static void TestLocal() { int desertSunId; using (var db = new LinqContext()) { var startCity = new Club { Name = "Star City Chess Club", City = "New York" }; var desertSun = new Club { Name = "Desert Sun Chess Club", City = "Phoenix" }; var palmTree = new Club { Name = "Palm Tree Chess Club", City = "San Diego" }; db.Clubs.Add(startCity); db.Clubs.Add(desertSun); db.Clubs.Add(palmTree); db.SaveChanges(); desertSunId = desertSun.ClubId; } using (var db = new LinqContext()) { Console.WriteLine("\nLocal Collection Behavior"); Console.WriteLine("==============="); Console.WriteLine($"\nNumber of Clubs Contained in Local Collection:{db.Clubs.Local.Count}"); Console.WriteLine("================"); Console.WriteLine("\nClubs Retrived from Context Object"); Console.WriteLine("================"); foreach (var club in db.Clubs.Take(2)) { Console.WriteLine($"{club.Name} is located in {club.City}"); } Console.WriteLine("\nClubs Contained in Context Local Collection"); Console.WriteLine("================="); foreach (var club in db.Clubs.Local) { Console.WriteLine($"{club.Name} is located in {club.City}"); } db.Clubs.Find(desertSunId); Console.WriteLine("\nClubs Retrived form Context Object - Revisted"); Console.WriteLine("==============="); foreach (var club in db.Clubs) { Console.WriteLine($"{club.Name} is located in {club.City}"); } Console.WriteLine("\nClubs Contained in Context Local Collection - Revisted"); Console.WriteLine("=============="); foreach (var club in db.Clubs.Local) { Console.WriteLine($"{club.Name} is localed in {club.City}"); } var localClubs = db.Clubs.Local; var lonesomePintId = -999; localClubs.Add(new Club { City = "Portland", Name = "Lonesone Pine", ClubId = lonesomePintId }); localClubs.Remove(db.Clubs.Find(desertSunId)); Console.WriteLine("\nClub Contained in Context Object - After Adding and Deleting"); Console.WriteLine("============="); foreach (var club in db.Clubs) { Console.WriteLine($"{club.Name} is located in {club.City} with a Entity State of {db.Entry(club).State}"); } Console.WriteLine("\nClubs Contained in Context Local Collection - After Adding and Deleting"); Console.WriteLine("============="); foreach (var club in localClubs) { Console.WriteLine($"{club.Name} is located in {club.City} with a Entity State of {db.Entry(club).State}"); } Console.WriteLine("\nPress <enter> to continue"); Console.ReadLine(); } }
public ExpenseDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public DebtCoverDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public ClientDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public InnerMovementDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public ReturnedSaleDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public SupplierDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }
public CompanyInfoDalFacade() { db = new LinqContext(LinqContext.DB_CONNECTION); }