Base solution for your next web application
Open Closed

Unique Key Constraints for multiple columns #1592


User avatar
0
jibbar created

I tried to create unique key constraints for two columns using below code but showing error.

[Index("IX_FirstAndSecond", 1, IsUnique = true)] public int FirstColumn { get; set; }

[Index("IX_FirstAndSecond", 2, IsUnique = true)] public int SecondColumn { get; set; }

Is there any system to create unique key constraints for multiple columns??


6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Your code seems correct. What error are you getting? If it can not find the Index atrribute, you need to add EntityFramework nuget package to the .Core project.

  • User Avatar
    0
    jibbar created

    Thanks a lot.

    Now raising another question,

    When using sqlBulkInsert for large data it's getting error if there any redundant data. Is there any solution that sqlBulkInsert will insert all unique data just skipping the row of error.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I think that's not directly related to AspNet Zore. Have you searched web for it?

  • User Avatar
    0
    jibbar created

    Dear,

    in new version, what need to use replace of [Index(IsUnique = true)]?

    this show error.

    Thanks

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Index is an attibute defined in EntityFramework, and not related to AspNet Zero. Have you added EntityFramework nuget package to your .Core project and added System.ComponentModel.DataAnnotations.Schema namespace to your code file?

  • User Avatar
    0
    jibbar created

    Hi,

    thans its working after install EntityFramework package.

    Thanks