Exemplo n.º 1
0
        private void ImportCountriesWithAliases()
        {
            using (var trans = new TransactionScope())
            {
                using (var tom = Engine.ServiceProvider.CreateEntityRepository())
                {
                    foreach (var record in CountryAliasRecords)
                    {
                        var lcid  = record.Item1;
                        var alias = record.Item2;

                        var country = tom.Countries.FirstOrDefault(c => c.LCID == lcid);
                        if (country == null)
                        {
                            country = new Country(lcid);

                            tom.Countries.AddObject(country);
                        }

                        if (!tom.CountryAliases.Any(a => a.Name == alias))
                        {
                            var countryAlias = new CountryAlias(country, alias);

                            tom.CountryAliases.AddObject(countryAlias);
                        }
                    }

                    tom.SaveChanges();
                }

                trans.Complete();
            }
        }
        public static string UsingPredefinedClasses()
        {
            var p = new PeopleAlias("p");
            var c = new CityAlias("c");
            var o = new CountryAlias("o");

            return(new SqlQuery()
                   .Select(p.Firstname)
                   .Select(p.Surname)
                   .Select(c.CityName)
                   .Select(o.CountryName)
                   .From(p)
                   .From(c)
                   .From(o)
                   .OrderBy(p.Age)
                   .ToString());
        }