CREATE TABLE [dbo].[Person] ( [Id] int PRIMARY KEY IDENTITY(1,1) , [Name] varchar(20) NULL , [Sex] varchar(20) NULL , [Phone] varchar(20) NULL , [Email] varchar(20) NULL )
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="mydb" connectionString="Data Source=.;Initial Catalog=mydb;Integrated Security=True" providerName="sqlserver"/>
</connectionStrings>
</configuration>
[Table(Key = "mydb")] public class Person : DataVeryLite.Core.Entity { [Column(Name = "Id", IsPrimaryKey = true)] public int Id { get; set; } [Column(Name = "Name")] public string Name { get; set; } [Column(Name = "Sex")] public string Sex { get; set; } [Column(Name = "Phone")] public string Phone { get; set; } [Column(Name = "Email")] public string Email { get; set; } }
private static void Main(string[] args) { var person = new Person(); person.Name = "天大地大"; person.Email = "[email protected]"; person.Save(); }
new Person {Id = 1, Name = "海阔天空"}.Update();
执行结果如下:
var personById = new Person(); personById.Load(By.Id(1)); Console.WriteLine(personById.Name + ":" + personById.Email);
结果如下:
Console.WriteLine("记录数:" + new Person().Count);
结果如下:
new Person(){Id = 1}.Del();
PM> Install-Package DataVeryLite
using System; public class HelloWorld { public static void Main(params string[] args) { var p=Models.Xe.Person(); p.Load(By.Id(1)); p.Del(); Console.WriteLine(p.Name+","+p.Age); } }