Juks
Juks
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
thanks a lot my man
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
got it
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
thanks, ill try to make it now
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
so to make it clear as i understand it
modelBuilder.Entity<Customer>().HasData(new List<Customer>
{
new Customer
{
CustomerId = 1,
CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland",
Email = "[email protected]",
PhoneNumber = "+48901234567"
},

});
modelBuilder.Entity<Customer>().HasData(new List<Customer>
{
new Customer
{
CustomerId = 1,
CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland",
Email = "[email protected]",
PhoneNumber = "+48901234567"
},

});
this is only way to do it because i always need to provide customer ID while seeding, you can't use auto incrementation here?
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
yh, but how to do it when i dont wan't to provide it
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
and btw thanks for your help you're legend
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
Exactly, so i provided class:
public class Customer
{
public int CustomerId { get; set; }

[Required]
public string CustomerType { get; set; }

[Required]
public string Address { get; set; }

[Required]
[EmailAddress]
public string Email { get; set; }

[Required]
[Phone]
public string PhoneNumber { get; set; }
}
public class Customer
{
public int CustomerId { get; set; }

[Required]
public string CustomerType { get; set; }

[Required]
public string Address { get; set; }

[Required]
[EmailAddress]
public string Email { get; set; }

[Required]
[Phone]
public string PhoneNumber { get; set; }
}
my insert looks like this:
modelBuilder.Entity<Customer>().HasData(new List<Customer>
{
new Customer
{
CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland",
Email = "[email protected]",
PhoneNumber = "+48901234567"
},
new Customer
{
CustomerType = "Company", Address = "707 Willow St, Gdansk, Poland",
Email = "[email protected]",
PhoneNumber = "+48101234568"
}
});
modelBuilder.Entity<Customer>().HasData(new List<Customer>
{
new Customer
{
CustomerType = "Company", Address = "606 Aspen St, Wroclaw, Poland",
Email = "[email protected]",
PhoneNumber = "+48901234567"
},
new Customer
{
CustomerType = "Company", Address = "707 Willow St, Gdansk, Poland",
Email = "[email protected]",
PhoneNumber = "+48101234568"
}
});
do i need to provide this part of code? I dont think thats the reason
await _myContext.Books.Add(newBook);
await SaveChangesAsync();
await _myContext.Books.Add(newBook);
await SaveChangesAsync();
In link you send there is a Example where we specify PK in model class
[PrimaryKey(nameof(State), nameof(LicensePlate))]
internal class Car
{
public string State { get; set; }
public string LicensePlate { get; set; }

public string Make { get; set; }
public string Model { get; set; }
}
[PrimaryKey(nameof(State), nameof(LicensePlate))]
internal class Car
{
public string State { get; set; }
public string LicensePlate { get; set; }

public string Make { get; set; }
public string Model { get; set; }
}
should'nt i do it like that?
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
yeah i know that, but could you provide me an example, i have no idea where to specify a PK
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
seeding means where?
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
The seed entity for entity type 'Customer' cannot be added because a non-zero value is required for property 'CustomerId'. Consider providing a negative value to avoid collisions with non-seed data.
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
when i didnt provide pk manually i get the same error
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
no it wont
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
so if i dont provide anything just leave this blind it will know it need to autoincrement ID?
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
yh it did work
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
let me check
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
so how should i do it then?
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
wym manually
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
i need to specify primary ket at the top of class in Models? and every goreign key like here?
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace APBD_kol2.Models;


[Table("backpacks")]
[PrimaryKey(nameof(CharacterId), nameof(ItemId))]
public class Backpacks
{
public int CharacterId { get; set; }
public int ItemId { get; set; }
public int Amount { get; set; }

[ForeignKey(nameof(CharacterId))]
public Characters Characters { get; set; }
[ForeignKey(nameof(ItemId))]
public Items Items { get; set; }

}
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace APBD_kol2.Models;


[Table("backpacks")]
[PrimaryKey(nameof(CharacterId), nameof(ItemId))]
public class Backpacks
{
public int CharacterId { get; set; }
public int ItemId { get; set; }
public int Amount { get; set; }

[ForeignKey(nameof(CharacterId))]
public Characters Characters { get; set; }
[ForeignKey(nameof(ItemId))]
public Items Items { get; set; }

}
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
exactly
49 replies
CC#
Created by Juks on 6/23/2024 in #help
Problem while "dotnet ef migrations add Init"
i made Insert for companyCustomer, i get diffrent error withnot specyfying pk
49 replies