我正在设计一个数据库,我想规范化数据库.在一个查询中,我将加入大约30-40个表.如果它变得非常受欢迎,这会损害网站性能吗?这将是主要查询,它将在50%的时间内被调用.我将加入关于两个表的其他查询.
我现在可以选择标准化或不标准化,但如果标准化将来成为问题,我可能需要重写40%的软件,这可能需要很长时间.在这种情况下,规范化真的会受到伤害吗 在我有空的时候,我应该现在正常化吗?
c# performance normalization denormalization sql-server-2008
看看我的代码:
public static ItemType GetItem(int id)
{
ItemType it = new ItemType();
using (var context = matrix2.matrix2core.DataAccess.Connection.GetContext())
{
var q = (from ci in context.Item
where ci.ID == id
let TemplateID = ci.TemplateID
let Groups = from x in context.CriteriaGroup
where x.TemplateID == TemplateID
select new
{
x
}
let CriteriaItems = from x in context.CriteriaItem
where Groups.Select(y => y.x.ID).Contains(x.CriteriaGroupID)
select new
{
x
}
select new
{
ci.ID,
ci.Name,
ci.CategoryID,
ci.Description,
ci.ItemValue,
TemplateID,
Groups,
CriteriaItems,
ItemValues = from x …Run Code Online (Sandbox Code Playgroud) 我需要在某些节点之前和之后移动兄弟节点.这是我正在使用的代码
<tabs>
<tab>
<name>Overview</name>
</tab>
<tab>
<name>Testing</name>
</tab>
<tab>
<name>Performance</name>
</tab>
<tab>
<name>Braking</name>
</tab>
</tabs>
Run Code Online (Sandbox Code Playgroud)
我想移动选项卡,在上面的概述中进行测试.我将如何使用linq to XML进行此操作?
我已经阅读了关于如何进行数据透视表的stackoverflow上的大多数帖子,但是所有帖子都显示了具有列的先验知识的示例.如果您不知道列将是什么,如何构造查询.这是一些示例数据:
id column value Row
1 age 13 1
2 height 55 1
3 fav number NULL 1
4 siblings 4 1
5 age 55 2
6 height 54 2
7 fav number 12 2
Run Code Online (Sandbox Code Playgroud)
我正在寻找这个输出:
row age height fav number siblings
1 13 55 NULL 4
2 55 54 12 NULL
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,没有第2行缺少兄弟姐妹的条目.查询时列名称未知.你会如何进行这个查询.
我有一个异步asp.net控制器.该控制器调用异步方法.实际执行异步IO工作的方法深入到我的应用程序中.控制器和链中最后一个方法之间的一系列方法都用async修饰符标记.以下是我如何设置代码的示例:
public async Task<ActionResult> Index(int[] ids)
{
List<int> listOfDataPoints = dataPointService(ids);
List<Task> dpTaskList = new List<Task>();
foreach (var x in listOfDataPoints)
{
dpTaskList.Add(C_Async(x));
}
await Task.WhenAll(dpTaskList);
return View();
}
private async Task C_Async(int id)
{
//this method executes very fast
var idTemp = paddID(id);
await D_Async(idTemp);
}
private async Task D_Async(string id)
{
//this method executes very fast
await E_Async(id);
}
private async Task E_Async(string url)
{
//this method performs the actual async IO
result = await new WebClient().DownloadStringTaskAsync(new Uri(url)) …Run Code Online (Sandbox Code Playgroud) 如果我有一个非常大的表,这个查询会在过滤重置之前将整个表加载到内存中:
with parent as
(
select * from a101
)
select * from parent
where value1 = 159
Run Code Online (Sandbox Code Playgroud)
如您所见,父查询引用整个表.这会加载到内存中.这是查询的一个非常简化的版本.真正的查询与其他表有一些连接.我正在评估sql server 2012和postgrsql.
我知道Linq提供了确定集合是否有任何项目的功能.如
var anyCategories= categories.Any();
Run Code Online (Sandbox Code Playgroud)
这非常有效,因为如果它找到至少一个项目,则迭代停止.现在如果我想知道一个集合是否至少有2个项目怎么办?这是我目前的代码:
var atLeastTwoCategories= categories.Count() > 1;
Run Code Online (Sandbox Code Playgroud)
如果计数大于1,那么这个将经历整个集合.我认为这是非常低效的.Linq或.NET是否提供了更好的方法?
我有多个布尔语句正在评估。它们按从上到下的顺序进行评估。一些布尔语句的评估成本很高,所以我对它们使用惰性。这是示例代码:
bool contactHasPermission = ContactHasPermission(id);
var contactIsInRole = new Lazy<bool>(() => IsContactInRole(contactId, roleType)); //Database call
var contactHasAtLeastXPoints = new Lazy<bool>(() => ContactHasXPoints(contactId, 100)); //database call
bool permit = contactHasPermission || contactIsInRole.Value || contactHasAtLeastXPoints.Value;
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,最昂贵的语句是在惰性对象中。我可以用 Func 做同样的事情。使用其中一种的优缺点是什么?
我到处搜索,没有任何解决方案。这是我插入数据的方式:
string value = db.StringGet("test");
string cleaned = value.Replace("u'", "'").Replace("\"", "");
var jsonDoc = Newtonsoft.Json.JsonConvert.SerializeObject(cleaned);
Dictionary<string, string> dict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonDoc);
values.Add(dict);
_collection.InsertMany(values.Select(x => x.ToBsonDocument()));
Run Code Online (Sandbox Code Playgroud)
这是数据在数据库中的外观
{
"_id" : ObjectId("5aaabf7ac03af44892673031"),
"_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson",
"_v" : {
"profile" : "myprofile",
"source" : "thesource",
"hostname" : "myhost",
"pgm" : "mypgm"
}
}
Run Code Online (Sandbox Code Playgroud)
我不希望在 mongo 中像这样格式化数据。我的原因是因为我有几个客户端访问数据库。我宁愿将数据格式化如下:
{
"_id" : ObjectId("5aaabf7ac03af44892673031"),
"profile" : "myprofile",
"source" : "thesource",
"hostname" : "myhost",
"pgm" : "mypgm"
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
var query = from row1 in table.AsEnumerable()
let time = row1.Field<DateTime>("time")
let uri = row1.Field<string>("cs-uri-stem")
let ip = row1.Field<string>("c-ip")
let questionid = row1.Field<int>("questionid")
where questionid == int.Parse(table.Rows[x]["questionid"].ToString())
select new
{
time,
uri,
ip,
questionid
};
Run Code Online (Sandbox Code Playgroud)
该IP列应该是唯一的.我不能在ip字段中有重复的项目.是否可以在linq中执行此操作
c# ×8
linq ×4
postgresql ×2
sql ×2
.net ×1
asp.net-mvc ×1
async-await ×1
datatable ×1
linq-to-xml ×1
mongodb ×1
mysql ×1
performance ×1
pivot ×1
sql-server ×1
xml ×1