我正在尝试映射具有多对多关系的Person和Address类.我想将Address集合映射为IDictionary,并将Address属性Type作为键.该关系仅从Person侧映射.
public class Person
{
public IDictionary<int, Address> Addresses { get; set; }
}
public class Address
{
public int Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我使用的映射是:
HasManyToMany<Address>(x => x.Addresses).Table("PersonAddress")
.ParentKeyColumn("PersonId").ChildKeyColumn("AddressId")
.AsMap(x => x.Type);
Run Code Online (Sandbox Code Playgroud)
问题是发出的SQL是:
SELECT addressesd0_.PersonId as PersonId1_,
addressesd0_.AddressId as AddressId1_,
addressesd0_.Type as Type1_,
address1_.AddressId as AddressId5_0_
-- etc.
FROM dbo.PersonAddress addressesd0_
left outer join dbo.Address address1_
on addressesd0_.AddressId = address1_.AddressId
WHERE addressesd0_.PersonId = 420893
Run Code Online (Sandbox Code Playgroud)
它试图从多对多连接表中选择Type,该表不存在.我已经尝试了一些映射的变体而没有成功.
我该如何映射?
当用户在根节点页面上时,如何在SiteMapPath控件中隐藏根节点?例如,我在子页面上的痕迹痕迹是:
主页>产品>锤子>球形喷丸
这很好.但是当用户在主页上时,将显示SiteMapPath控件
家
这是无用的混乱.我想在用户在主页上时禁止显示Home(根节点).我在母版页中有SiteMapPath控件.另外,我正在处理SiteMapResolve以在节点中设置查询字符串.
我有一个继承自的IRepository接口IRepository<TObject>.我还有一个继承自S的SqlRepository类,而S QLRepository<TObject>又实现了IRepository<TObject>.为什么我不能将SqlRepository的实例实例化为IRepository?
public class MyObject : IObject {
...
}
public interface IRepository<TObject> where TObject : IObject, new() {
...
}
public interface IRepository : IRepository<MyObject> { }
public class SqlRepository<TObject> : IRepository<TObject> where TObject : IObject, new() {
...
}
public class SqlRepository : SqlRepository<MyObject> { }
public class Controller {
private IRepository _repository;
public Controller() {
_repository = new SqlRepository();
}
}
Run Code Online (Sandbox Code Playgroud)
尝试将新的SqlRepository分配给Controller类中的_repository时,上面的示例失败,并显示以下错误消息.
Argument '1': cannot convert from 'SqlRepository' to 'IRepository'
Run Code Online (Sandbox Code Playgroud)
我没有掌握哪种基本的继承原则,请帮忙.
我有几个简单的数据库查询使用Entity Framework我想加载一次,Lazy<T>但我可以看到每次调用属性时执行查询.我尝试的变化是:
public static IEnumerable<string> Foos => new Lazy<IEnumerable<string>>(() => _db.Foos.Select(x => x.Name)).Value;
public static IEnumerable<string> Foos=> new Lazy<IEnumerable<string>>(() => _db.Foos.Select(x => x.Name).ToArray()).Value;
public static Lazy<IEnumerable<string>> Foos => new Lazy<IEnumerable<string>>(() => _db.Foos.Select(x => x.Name).ToArray());
public static IEnumerable<string> LightingEnvironments
{
get
{
var lazy = new Lazy<IEnumerable<string>>(() => _db.Foos.Select(x => x.Name).ToArray());
return lazy.Value;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个与业务类交互的ASP.NET页面.我想根据用户输入的值不断更新页面上的控件,例如更新总计.计算嵌入在业务逻辑中,但它们很简单,可以在其他地方重现.我想到了三种方法来实现这个目标:
第三种方法对我来说似乎最干净,提供了良好的用户体验,并允许我直接与我在会话状态中存储的业务类进行交互.
我的问题是:这是一个好主意和/或一个普遍的做法吗?有没有更好的方法来实现这一目标?
我几年没有完成ASP.NET工作,我对autopostback有偏见[1].我已经查看了请求的大小,目前在1.5kB时可以忽略不计.该网站使用率较低,但我们可能会有少量用户使用拨号连接.
asp.net ×2
c# ×2
asp.net-ajax ×1
inheritance ×1
master-pages ×1
nhibernate ×1
repository ×1
sitemap ×1