目前我正在使用以下代码块动态创建DbSet并从中检索数据 -
Type entityType = Type.GetType("MyProject.Models."+ EntityName + ", SkyTracker");
DbSet mySet = Db.Set(entityType);
foreach (var entity in mySet)
{
}
我想在这里使用Where子句,即.Where(m=>m.Id==1)
或类似的东西。
有什么办法吗?
答案 0 :(得分:1)
你应该在这里使用泛型来简化它。
<!DOCTYPE html>
<html>
<head>
<link rel = stylesheet href = Father.css>
<title> Very Important Company </title>
</head>
<body>
<div id = backs </div>
<div class = header>
<p>
<img src = http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png id = gecko>
</p>
<div class = navigation>
<ul>
<li> SHOP </li>
<li> ABOUT US </li>
<li> RENTALS </li>
<li> CONTACT </li>
<li> PARTIES </li>
</ul>
</div>
</div>
<p>
<div class = main>
<p1> Our Eggs
</p1>
</div>
</body>
</html>
您可以按照以下方式调用这些方法。
* {
margin: 0;
padding: 0;
}
#backs {
background: white;
}
#gecko {
content:url(http://www.unixstickers.com/image/data/stickers/opensuse/Opensuse-logo-wob.sh.png);
height: 128px;
width: 128px;
position: relative;
float: left;
margin-left: 10px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: inline;
}
li {
display: inline;
padding-left: 50px;
min-width: 100%
}
.navigation {
color: black;
letter-spacing: 2px;
float: right;
vertical-align: top;
width: 800px;
height: 70px;
margin-top: 47px;
min-width:800px;
padding-left: 150px;
position: absolute;
}
.main {
color: black;
font-size: 60px;
position: relative;
top: 150px;
background-image: url (http://files.vividscreen.info/soft/fc5e9b0dc8833c69951d28bb856b9ef4/Decorated-Easter-Eggs-2880x1920.jpg);
min-width: 100%;
height: 900px;
border: 2px solid red;
padding-top: 100px;
}
这里public DbSet<T> GetDbSet<T>() where T: class
{
DbContext db = new DbContext("");
return db.Set<T>();
}
public List<T> GetFilteredData<T>(Expression<Func<T, bool>> criteria) where T : class
{
DbContext db = new DbContext("");
return db.Set<T>().Where(criteria).ToList();
}
只是我创建的示例类。
这可以帮助您实现您想要的行为。