質問

i want to set a property value in a table to default auto increment,but their are no options to do so in lightswitch2012 to my knowledge which is given that i recently started learning lightswitch,very light.

ok heres the real problem,this is the table

[customer][id,customer_id,name]

i want to set customer_id by default to id unless it is manually changed to different value.

how to acheive this?

役に立ちましたか?

解決

In the Entity designer make your Customer_ID not required. Write Code for Customers_Inserted.

Then, check to see if the Customer_ID is null. If it is, copy the ID field to it.

private void Customers_Inserted(Customer entity)
{
    if (entity.Customer_ID == null) {
        entity.Customer_ID = entity.ID;
    }
}

他のヒント

You're right, there is no "auto-increment" data type available in LightSwitch. The ID property auto-increments, but that's a special case, handled by LightSwitch.

If you were attaching to an external SQL database, if you added a column that was an Integer Identity column, although it'll just appear as an Integer property in LightSwitch, it would still auto-increment because that's actually done in the SQL database itself.

The problem with all auto-increment properties is that you won't get the actual value until the record is saved.

Can I ask why you need an auto-increment property?

I may be misunderstanding what you are trying to achieve, but if you are using either a table or a grid, and you want to set the values for various entities for each new row your user adds (like customer_id = id, etc.), you can use the _Changed method and Add event to programmatically set any of the new row entities.

If this is along the lines of what you're looking for, watch Beth Massi's video How Do I: Copy Data from One Row into a New Row? You should be able to adapt her code to accomplish what you have in mind I think.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top