通过局部类重命名LINQ 2 SQL实体属性 [英] Renaming LINQ 2 SQL Entity Properties Through Partial Classes
本文介绍了通过局部类重命名LINQ 2 SQL实体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用部分类创建指向L2S设计器生成的关联属性的属性.另外,我可以在查询中使用new属性吗?
Can I use partial classes to create properties that points to an association property generated by the L2S designer. Also, will I be able to use the new property in queries?
我该如何实现?
推荐答案
是的,但是您必须应用与linq2sql生成的属性相同的属性,即
Yes you can, but you have to apply the same attributes as the linq2sql generated property i.e.
[Association(Name="Test_TestData", Storage="_TestDatas", ThisKey="SomeId", OtherKey="OtherId")]
public System.Data.Linq.EntitySet<TestData> MyTestDatas
{
get
{
return this.TestDatas;
}
}
TestDatas是原始关系.
TestDatas being the original relation.
更新:我运行的示例查询:
Update: A sample query I ran:
var context = new DataClasses1DataContext();
var tests =
from d in context.Tests
where d.MyTestDatas.Any(md=>md.MyId == 2)
select new
{
SomeId = d.SomeId,
SomeData = d.SomeData,
Tests = d.MyTestDatas
};
foreach (var test in tests)
{
var data = test.Tests.ToList();
}
这篇关于通过局部类重命名LINQ 2 SQL实体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文