快速提问我是Visual Studio和ASP.net网络表单的新手。
我使用代码优先方法构建数据库,我想知道是否可以将图像添加到数据库中,如果是这样,我将如何链接它们
这是变量,你可以看到我混合了字符串和整数
现在我想知道你是否可以用同样的方式添加图像值
public string SuperName { get; set; }
public string NormalName { get; set; }
public int Age { get; set; }
public string Role { get; set; }
public string Location { get; set; }
public int NumAppearances { get; set; }
public string Description { get; set; }
这里填写了所有变量
IList<Character> defaultCharacters1 = new List<Character>();
defaultCharacters1.Add(new Character() { SuperName = "Iron Man", NormalName = "Tony Stark", Age = 49, Role = "Hero", Location = "New York", NumAppearances = 5, Description = "An American billionaire playboy, industrialist, and ingenious engineer, Tony Stark suffers a severe chest injury during a kidnapping in which his captors attempt to force him to build a weapon of mass destruction. He instead creates a powered suit of armor to save his life and escape captivity. Later, Stark augments his suit with weapons and other technological devices he designed through his company, Stark Industries. He uses the suit and successive versions to protect the world as Iron Man." });
此处是我的数据库显示信息的当前屏幕截图
任何帮助都会很棒
答案 0 :(得分:0)
最好的方法是将图像上传到外部存储,例如Azure Blob存储(如果存在,则可以备份图像),然后通过EF将链接保存到SQL中。 / p>
在SQL中保存BLOB(图像是BLOB)可能会导致错误的碎片,并且会逐渐减慢数据库的速度。这就是为什么BLOB存储在SQL DB之外的原因。
数据库中图像的另一个缺点是,在整个应用程序中,您将从后到前放置大量的流量 - 并且您将大大减慢您的网站速度。相反,如果您将它们放置在外部BLOB存储中,您将提供一个链接,该更明亮的链接将从不同位置加载,从而提高您网站的整体速度。
所以不要在SQL中存储图像,即使你可以将它们存储在binary列中,甚至可以存储在base64编码后的varchar列中。 (你从来没有听过我建议:))。将它们存储在某种BLOB存储上 - Azure,Amazon,Picasa ......等等,只保存它们在SQL db中的URL。