如何获取仅包含字符串名称的 Set Linq 实体

发布于 2025-01-04 16:56:54 字数 511 浏览 3 评论 0原文

好的,我有 linq 实体的字符串名称。

string table = "Person";

我有数据上下文,并且有一个名为 Person 的实体或数据库表。

我想以某种方式使用表名的字符串创建一个新的 Person 实体并设置所有属性。

对于这个例子,我确实没有太多代码,但让我尝试写一些东西。

MetaTable table = SetTable(); //Gets the metatable of the entity
string tableName = table.TableName; //"Person"
//Stuck there
//...
//What I'd like to do
//Somehow get Person then
Person p = new Person();
p.Name = "Joe";
db.Person.InsertOnSubmit(p);
db.SubmitChanges();

谢谢

Okay so I have the string name of the linq entity.

string table = "Person";

I have the datacontext and there's an entity or database table called Person.

I'd like to be about to somehow using the string of the table name create a new Person entity and set all the attributes.

I really don't have much code for this example but let me try and write something.

MetaTable table = SetTable(); //Gets the metatable of the entity
string tableName = table.TableName; //"Person"
//Stuck there
//...
//What I'd like to do
//Somehow get Person then
Person p = new Person();
p.Name = "Joe";
db.Person.InsertOnSubmit(p);
db.SubmitChanges();

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷夜 2025-01-11 16:56:54

尝试这种方式获取数据

AdventureWorksDataContext dataContext = 
            new AdventureWorksDataContext();

        var query = from contact in dataContext.Contacts
                  select contact;

Try This way to get data

AdventureWorksDataContext dataContext = 
            new AdventureWorksDataContext();

        var query = from contact in dataContext.Contacts
                  select contact;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文