简体   繁体   中英

How to use InsertOnly method in OrmLite?

Following this example, how is the correspondent for the method InsertOnly?

var updated = await dbCon.UpdateOnlyAsync(timesheet,
onlyFields: 
    x =>
        new
        {
            x.LogInTime,
            x.LogOffTime,
            x.IsFlaggedByLeader,
            x.LeaderComment,
            x.IsModified
        },
@where: x => x.Id == timesheet.Id) > 0; 

I couldn't find an example on Internet and in the Ormlite documentation.

You can find some examples in ApiSqlServerTests , eg:

db.InsertOnly(() => new Poco { FirstName = "Amy", Age = 27 });

db.InsertOnly(new Poco { FirstName = "Amy", Age = 27 }, 
    p => new { p.FirstName, p.Age });

db.InsertOnly(new Poco { Age = 27 }, p => p.Age);

db.InsertOnly(new Poco { FirstName = "Amy", Age = 27 }, 
    new[] { "FirstName", "Age" });

and async versions in ApiSqlServerTestsAsync , eg:

await db.InsertOnlyAsync(() => new Poco { FirstName = "Amy", Age = 27 });

await db.InsertOnlyAsync(new Poco { FirstName = "Amy", Age = 27 }, 
    p => new { p.FirstName, p.Age });

await db.InsertOnlyAsync(new Poco { Age = 27 }, p => p.Age);

await db.InsertOnlyAsync(new Poco { FirstName = "Amy", Age = 27 }, 
    new[] { "FirstName", "Age" });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM