last day (166 days later) » 

3:43 AM
Starting up this room to further hash out Shawn Watson original question on SO
https://stackoverflow.com/questions/64143014/the-property-propertyname-could-not-be-mapped-because-it-is-of-type-liststr/64143122?noredirect=1#comment113436067_64143122
@Shane Watson....sorry for the original flub on name.
 
 
2 hours later…
6:03 AM
this link I followed for creating upload multiple images.but when i create this model I found an error that I posted.
 
 
7 hours later…
1:04 PM
@ShaneWatson Shane...first of all I just wanna say that by no means am I an expert at all. Also...EF is still evolving...and IMO has a way to go.
 
1:51 PM
This is your Shop class ...I made some changes. All changes are from mistakes I made.
public class Shop
{
[Key]
public int ShopId { get; set; }

[Required]
[StringLength(50)]
[Display(Name = "Product Name")]
public string Name { get; set; }

[Required]
[Column(TypeName = "decimal(18, 2)")]
public decimal Price { get; set; }

[StringLength(50)]
public string Image { get; set; }

[NotMapped]
public List<string> Photos { get; set; }

[Required]
public int Quantity { get; set; }

[Required]
public bool IsAvailable { get; set; }

[Display(Name = "Category")]
[ForeignKey("CategoryTypeId")]
The first change I made was to change "ID". At first it seems harmless...but once the table structures start accumulating and you start writing more and more routes...have a meaningful key name is benificial.
The second thing is to put a length on the string...EF will make it nvarchar(Max) in the database.
 
2:13 PM
For your list of images you will need another table.
public class ShopImage
{
[Key]
ShopImageId {get,set}

[ForeignKey("Shop")]
public ShopId { get; set; }

[Required]
[StringLength(50)]
public string Image { get; set; }
}
The table ShopImage has a non-unique ForeignKey ShopId that relates bact to Shop
 
2:50 PM
I am really glad to find a helpful hand.Really admirable.
I could not find the relation between the ShopImage and Shop class.I created our shop class I did migration and update. if I don't relate to this
image or image class whatever, how I create a multiple image input file?if you looked at the above link, I think you understand what I actually want.if we create successfully a small demo of multiple image model and other .
then we could be easily creating many complex facts.

the first target, we have to create a database/model for store multiple/many images.
 
3:19 PM
Shop and ShopImage are related in the database by the Foreign key (ShopId) in ShopImage. I suppose you could also add the class Shop to ShopImage like this
public class ShopImage
{
[Key]
ShopImageId {get,set}

[ForeignKey("Shop")]
public ShopId { get; set; }
publis Shop Shop {get;set;}
[Required]
[StringLength(50)]
public string Image { get; set; }
}
The SQL for the relation would look something like:
Select ProductName,Price,ShopImage.Image
FROM Shop
JOIN ShopImage on ShopImage.ShopID = Shop.ShopID
WHERE Shop.ShopID = 12345
The sql would return you a result set with multiple records for that one particular ShopId and you could then use that to build the List<string> Photes in Shop model.
BTW...In you models use string (a primitive type) as opposed to String ( the class ).
 
4:08 PM
actually, I didn't my database course yet.I am learning to project on my own.I have a little bit of knowledge of the SQL server to create a database.if you clarify your two model's relationships code and give it, then I would be joyful.
 
4:51 PM
You should have everything you need. Just do the migrations and look at the tables in MSsqlServerManagerStudion (SSMS).
 
 
3 hours later…
7:42 PM
Thanks a lot.finally solved.
 
 
1 hour later…
8:46 PM
One thing I wanted to mention...If your using SSMS...you can open the XEvent Profiler and open the TSQL window and you'll be able to see the TSQL that EF is generating...not alway what you expect.
 

  last day (166 days later) »