Taqi Gates
Taqi Gates

Reputation: 87

Check wheather the column in a particular table has a value with Entity framework

if(ds.dt.Rows[0][0].ToString() != "") is traditional datatable method I need the same with entity framework. I need to check the admissionNo in a table Admission if it is empty for the first time I will generate if not it is generated next value of that (+1).

Upvotes: 0

Views: 76

Answers (2)

Sateesh Pagolu
Sateesh Pagolu

Reputation: 9606

The code below should help

 Var admissionNo = ctx.Admission.Any() && !String.IsNullOrEmpty(ctx.Admission.First().AdmissionNo)?Convert.ToInt32(ctx.Admission.First().AdmissionNo)+1 : 1;    

Upvotes: 1

WAQ
WAQ

Reputation: 2626

var generatedValue = 0;
var firstAdmission = context.Admission.FirstOrDefault();
if(firstAdmission == null)
    return;
if(!firstAdmission.AdmissionNo.HasValue)
    generatedValue = 123; // Whatever logic u have to generate a value
else
    generatedValue= AdmissionNo.Value + 1;

This code assumes that the admissionNo is a Nullable integer type

Upvotes: 0

Related Questions