Если вам нужен хороший универсальный метод для извлечения данных о сборке, попробуйте следующее:
public string GetAssemblyAttribute<T>(Func<T, string> value)
where T : Attribute
{
T attribute = (T)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof (T));
return value.Invoke(attribute);
}
, так что вы можете затем вызвать
string title = GetAssemblyAttribute<AssemblyTitleAttribute>(a => a.Title);
string copyright = GetAssemblyAttribute<AssemblyCopyrightAttribute>(a => a.Copyright);
string version = GetAssemblyAttribute<AssemblyVersionAttribute>(a => a.Version);
string description = GetAssemblyAttribute<AssemblyDescriptionAttribute>(a => a.Description);
As far as I know auto_increment does not fill gaps between ids and the operation is atomic. So you can assume that they will be in a row.
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id
If you insert multiple rows using a single
INSERT
statement,LAST_INSERT_ID()
returns the value generated for the first inserted row only.
So no, you can't get all the ids easily, but you can assume that they are continuous. You should never rely on assumptions though. It sounds like you want to guess the next id
that would come after your bulk insert? If so, do not even attempt this and think of another way to do whatever it is you want to do. :)
Чтобы получить следующий идентификатор auto_increment, вы можете использовать:
SELECT auto_increment FROM information_schema.tables WHERE table_name = 'table-you-want-to-check';
Однако вы можете не захотеть полагаться на auto_increment
id или last_insert_id ()
в логике вашего кода. Например, предположим, что два человека, A и B, добавляют вопросы в вашу базу данных почти в один и тот же момент, и вы используете last_insert_id ()
для определения идентификатора вопроса человека. Что происходит, когда они оба задают вопрос одновременно? last_insert_id ()
от человека A или B?
Одним из способов решения этой проблемы является использование «предопределенного»